Python on Nested List

Hi,

i have a 2 sets of lists, the first one is from the spreadsheet which indicates the sizes of pit structures, the other one is a nested list “Pipe Network Sizes”. I tried to create a Python script to match the sizes from the spreadsheet and create a new set of list equivalent to its Part Size using the index. The scripts that i made doesn’t evaluate the “if” statement and always went into the “else” statement and returns all the first index in every set of list.
Can anyone help me or suggest me if my script is right?

this is the pyhton script:

Regards,
Daneson

can you provide the files for testing? im think what you are trying to achieve could be simpler.

best

Hi Yien,

Thank you for your response. These are the Dynamo and Excel file
Appin Road Output for Dynamo Test.xlsx (30.4 KB) Swap Structure Attempt.dyn (187.5 KB)

and here is the link for the dwg file : Drawing File

To answer your question, you need another for loop like:

for Pit in Pit_Data:
    for y in range(len(Pit_Size)):

Your original for loop is also incorrect as you’re using the values in the range, not the values in Pit_Size. I think you actually want:

for y in Pit_Size:

However, all you really need is a dictionary. Lookup how to setup and use dictionaries and that should be exactly what you’re looking for without the hassle of writing python code.

1 Like

Hi Nick_Boyts,

I Appreciate for your response. I try to used the loop you mentioned. Do i have to evaluate first the Pit_Data list?

and error comes out in the image.

Error

I am using the C3D Toolkit Dictionaries and it seems that this are the only nodes available. I am still newbie in the DYnamo Programming.