Iterate over lists


I have a question that im sure some one here can answer. I have 2 lists currently and i need to iterate over the first list but then pass the second list into that. So, select first item in list 1 than iterate over list 2’s first sublist, select list 1 second item and iterate through list 2’s second sublist. Image below

I hope i explained it clearly.



If I’ve understood you properly, it should be straight forward



Thanks for the response Vikram but that’s not exactly what i’m trying to do. I have a python script that is taking in list 1 index 1 and running list 2 index 2(sublists) through it then list 1 index 2, list 2 index 2(sublists). Does that make sense.



I am guessing you have 2 sublists and really what you’re asking is how can you perform cross product lacing with sublist 1 against sublist 2?

Try this (this only works on a list with two sublists; if you are trying to match each item from sublist 1 with all items with sublist 2, then match each item from sublist 2 with all items from sublist 3…etc then this wont work and you should think about how to manage your data better)

import clr
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

list = IN[0]

concat = []

for i in range( len(list[0]) ):
	sub = []
	for j in list[1]:

#Assign your output to the OUT variable.
OUT = concat
1 Like

Python Nodes Basics

Your intent is still not clear to me.
Maybe @Thomas_Mahon’s cross product suggestion is all that you require.



Thanks for all the responses but i must work on giving you guys a better explanation of what i’m looking for. I ended up figuring out what i needed. I had different size list so i just made them all the same size and then after i removed what i didn’t need. Again thanks for all the help!



@nathan.chapman Would you mind posting the problem and your solution.
Curious as to what the issue actually was.



Below is the image of the custom node i came up with.

So the problem is that each group Index could have a different length of numbers associated with them. So what i did was just look at the groups and find the longest list and input that into the others. Within python it would throw an exception so i would just have it write something at that index to everything stays lined up. Then i chopped the list up. I hope that helps explain.



Thanks, but it would be better to see the list/s that you started with and the result that was obtained.
That might help understand what you were trying to do.