Lacing on replacing item on index

hello, I am trying to replace a list of items at a list of indices into a list of elements. I am sure I am having problems with lacing, but i cant figure out what it is. Can anyone help me please? I originally had a list of 49 elements. I removed the 12 elements that I want to replace and then am trying to insert the new elements into those same places. Does that make sense? I tried the replace items at index but had the same lacing issues. Please advise.

Is there a reason you are not using the List.ReplaceItemAtIndex node, rather than removing the 12 items that you wanted to replace first?

Also, I don’t think this is a lacing issue, since your list is 37 items and 12 is less than 37.

What are you feeding into the “index” input on the Insert node?

1 Like

It’s not a lacing issue. It’s an index issue. You have 37 items but you have indices outside of that range.
What you really want is to replace the item at the specified index, but I’m guessing you ran into issues with that so tried this instead. I would suggest using Python if you’re trying to replace multiple items at multiple indices in the same list.

1 Like

I tried the replace items at index nodes already. Same issues. I am feeding the list of indicies into the index node. (you can see them in the “Flatten” node connected to the “Index” import above. :confused


Yes, that is exactly what I am trying to do! unfortunately that I dont have any python skills. Are there any packages out there that can do this? it seems like it would be a fairly common issue. no? Thanks

Thanks, but what I am really trying to do is:

Clockwork has ReplaceItemAtIndex+ that does just this. Or you can look at this Python code that does the same thing.

dataEnteringNode = IN
list = IN[0]
elements = IN[1]
indices = IN[2]
count = 0
i = 0
out = []
for item in list:
		if count == indices[i]:
			i = i+1
			count = count+1
			count = count+1		
		count = count+1

OUT = out

Jackpot! Thanks Nick!

Andreas actually uses a much nicer method for replacing items.

dataEnteringNode = IN
list = IN[0]
elements = IN[1]
indices = IN[2]

for e,i in zip(elements,indices):

OUT = list

The simplicity of Python still amazes me at times.


Its not working for me. Do I have to flatten all the lists going into these python scripts?

@Nick_Boyts your last one will go out of index… you need to pad


list1 = IN[0]
list2 = IN[1]
index = IN[2]

def pad(var, length):
    return var[:length] + [None]*(length - len(var))

pad(list1, len(list1) + len(list2) )
for idx, item in zip(index,list2):
    list1.insert(idx, item)

OUT = list1

Those are both setup for one list of elements with one one list of replacements. You’d have to modify the code a bit to take multiple lists.

Seems to work for me with a simple test case.

yeah it did for me too. I just think its a flattening or a lacing issue

that’s because you have the length defined before you start changing items… if you have a list of length 6 and want to add 4 items at specific index… you need to pad the list to size 10

I read the problem as… a list of 37 items that need 12 items to be added (at specific index), so the list end at 59 elements

It’s hard to tell what the issue is when we can’t see any of your inputs. You might have more control using the node from Clockwork.

But for replacing items you should be fine as long as your indices are within range.

Here you go its really hard with such a small screen:

I am sure that will go wrong…
the list is of 37 elements and 12 to be added at specific index, not to be replaced… but i might read the question wrongly