# Best Practice for Looping though nested lists

**URL:** <https://forum.dynamobim.com/t/best-practice-for-looping-though-nested-lists/42743>\
**Category:** FAQ\
**Tags:** revit, clockwork, python, dynamo\
**Created:** [November 5, 2019, 9:42am UTC](https://forum.dynamobim.com/t/best-practice-for-looping-though-nested-lists/42743 "2019-11-05T09:42:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Gaydon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/matt_gaydon/32/78469_2.png) [@Matt\_Gaydon](https://forum.dynamobim.com/u/Matt_Gaydon)\
**Post date:** [November 5, 2019, 9:42am UTC](https://forum.dynamobim.com/t/best-practice-for-looping-though-nested-lists/42743/1 "2019-11-05T09:42:52Z")

</div>

What would be the best practice for looping thought nested lists for a code where you are changing parameters etc in Revit. I have found a few useful nodes including Element.SetSubCategory from the Clockwork package that are written to take a single list and not a nested list. As inside the node in flattens the list into a single 2D array before doing into the python code.

I have seen some people propose to put the main code in a definition then call this per nested list, while others would add the nested listing logic into the definition itself. With both these options there needs to be a way to have the nested lists as variable lenghts for the different inputs if possible.

Taking the previously mentioned node the Input,  
Element maybe a nested list  
SubCategory maybe a nested list but only have one item per level vs the Element which might have multiple.  
CutOrProject (Boolean) maybe nested or could be a single value for all where you don’t want to repeat lots of times.

This maybe possible using a Zip / dictionary logic i need to check.

This is another code i have found that i have been using that would be great to understand how to make work on nested lists. I see it already has dictionaries and using Zip so maybe it better to loop the whole definition than to write within current code

> [@Associate family parameter in a family](https://forum.dynamobim.com/t/associate-family-parameter-in-a-family/19709/17):
>
> oh my… your suggestion… look at the output. the list order changes … sometimes … look at [0][1] which has merk, start\_lagenmaat which the script will try to pair this up with [0][2] start\_lagenmaat, Description … well, that obvious won’t work. My yesterday’s screencast show several elements not being assigned … well, now we know why. Next step, figuring out why python changes the order of the list. I’m going to try a zip alternative … unsure if python libraries could cause this issue? (how t…
