Swap items in a list with items from another list on certain indexes

Hello!

I need help with a certain node called List.ReplaceItemAtIndex. As you can see on the picture below I have 2 sets of lists. One has 77 ‘null’ values and the other has 65 values of different string (P1, P2 etc). What I would like to do is swap values on the selected indexes in list with null values with values from list that contains P1, P2 etc. But no matter how I use List.ReplaceItemAtIndex (using levels etc) I cant get it done correctly. I have also tried with Dictionary nodes but couldnt find a solution.

Please help! Seems like an easy problem but I’ve spent last few hours just trying to figure it out.

Thank you, Domen

Found a soultion. I’ve used node from Clockwork package called 'List.ReplaceItemAtIndex+

Place a Python Script node with two input ports. Connect first list, the list with nulls, to first port and second list, list with P1,P2,P3 etc…, to second port. Inside the Python node, delete everything and just add this one line;

OUT = [IN[1][i] if IN[0][i] == None else IN[0][i] for i in range(len(IN[0]))]

1 Like