# Iterate over lists

**URL:** <https://forum.dynamobim.com/t/iterate-over-lists/4956>\
**Category:** Lists-Logic\
**Created:** [July 8, 2016, 4:02pm UTC](https://forum.dynamobim.com/t/iterate-over-lists/4956 "2016-07-08T16:02:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathan.chapman](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nathan.chapman/32/145024_2.png) [@nathan.chapman](https://forum.dynamobim.com/u/nathan.chapman)\
**Post date:** [July 8, 2016, 4:02pm UTC](https://forum.dynamobim.com/t/iterate-over-lists/4956/1 "2016-07-08T16:02:26Z")

</div>

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  
 ![](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex022/uploads/dynamobim/original/2X/6/65d7033ef3c97e20f2706405f3166dff1782ffa9.png)  
I hope i explained it clearly.

---

<div class="post-metadata">

**Author:** ![Vikram\_Subbaiah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vikram_subbaiah/32/50797_2.png) [@Vikram\_Subbaiah](https://forum.dynamobim.com/u/Vikram_Subbaiah)\
**Post date:** [July 8, 2016, 4:16pm UTC](https://forum.dynamobim.com/t/iterate-over-lists/4956/2 "2016-07-08T16:16:51Z")

</div>

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

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/2X/7/7cc0e1cc8282fd9e40b21edc8a195b4077ab8bb5.png)

---

<div class="post-metadata">

**Author:** ![nathan.chapman](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nathan.chapman/32/145024_2.png) [@nathan.chapman](https://forum.dynamobim.com/u/nathan.chapman)\
**Post date:** [July 8, 2016, 8:26pm UTC](https://forum.dynamobim.com/t/iterate-over-lists/4956/3 "2016-07-08T20:26:05Z")

</div>

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.

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/2X/a/a02abd3665e2dbc09bb300146ac62cc5078c8571.png)

---

<div class="post-metadata">

**Author:** ![Thomas\_Mahon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/thomas_mahon/32/64209_2.png) [@Thomas\_Mahon](https://forum.dynamobim.com/u/Thomas_Mahon)\
**Post date:** [July 9, 2016, 11:58am UTC](https://forum.dynamobim.com/t/iterate-over-lists/4956/4 "2016-07-09T11:58:33Z")

</div>

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
clr.AddReference('ProtoGeometry')
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]:
		sub.Add(str(i)+j);
	concat.Add(sub)

#Assign your output to the OUT variable.
OUT = concat
```

---

<div class="post-metadata">

**Author:** ![Vikram\_Subbaiah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vikram_subbaiah/32/50797_2.png) [@Vikram\_Subbaiah](https://forum.dynamobim.com/u/Vikram_Subbaiah)\
**Post date:** [July 12, 2016, 8:25am UTC](https://forum.dynamobim.com/t/iterate-over-lists/4956/5 "2016-07-12T08:25:30Z")

</div>

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

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/2X/1/1974fb7c6139557755ae2f12f597d4491cdf203f.png)

---

<div class="post-metadata">

**Author:** ![nathan.chapman](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nathan.chapman/32/145024_2.png) [@nathan.chapman](https://forum.dynamobim.com/u/nathan.chapman)\
**Post date:** [July 13, 2016, 2:20pm UTC](https://forum.dynamobim.com/t/iterate-over-lists/4956/6 "2016-07-13T14:20:12Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Vikram\_Subbaiah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vikram_subbaiah/32/50797_2.png) [@Vikram\_Subbaiah](https://forum.dynamobim.com/u/Vikram_Subbaiah)\
**Post date:** [July 14, 2016, 5:52am UTC](https://forum.dynamobim.com/t/iterate-over-lists/4956/7 "2016-07-14T05:52:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nathan.chapman](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nathan.chapman/32/145024_2.png) [@nathan.chapman](https://forum.dynamobim.com/u/nathan.chapman)\
**Post date:** [July 14, 2016, 12:58pm UTC](https://forum.dynamobim.com/t/iterate-over-lists/4956/8 "2016-07-14T12:58:00Z")

</div>

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

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/2X/4/491b73c3b5730ec95b7339cd1ab7bfe240e71c10.png)  
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.

---

<div class="post-metadata">

**Author:** ![Vikram\_Subbaiah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vikram_subbaiah/32/50797_2.png) [@Vikram\_Subbaiah](https://forum.dynamobim.com/u/Vikram_Subbaiah)\
**Post date:** [July 14, 2016, 1:09pm UTC](https://forum.dynamobim.com/t/iterate-over-lists/4956/9 "2016-07-14T13:09:47Z")

</div>

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.
