How to combine 2 lists in a specific order

Hi I have 2 lists and I’d like to combine them so that the wall at index 0 in my image is after quad 0 in the top list and so the wall at index 1 is inserted after index item 1 in the above list and so on is there any way to do that in python or dynamo?

image

Yes you could put them both into a python node then have some loop with an iterator and add an item from each list alternating based on whether the iterator is even or odd. It would look something like:

list1 = IN[0]

list2 = IN[1]

newlist=

a = 0

b = 0

x=0

for x in range ((len(list1)+len(list2)):
if (x%2 == 0):
newlist.append(list1(a))
a = a+1
x = x+1
else:
newlist.append(list2(b))
b = b+1
x = x+1
OUT = newlist

Syntax might be wrong, I haven’t tried it out

Easier method is using List.Create and then a Transpose node:

and another python example:
OUT = [[a,b] for a,b in zip(IN[0],IN[1])]
python%20transpose

Edit: If you need them all in the same list, you can just flatten afterwards.

2 Likes

Thanks this works.