Get item at index using loop

Hi,
I am trying to get items from a list, based on the index values. Instead of using the complete list, I want to work with index [0], perform some analysis, and repeat the steps for other index values till the condition is met.

I tried using the while loop, but the analysis is performed only at the last index. Here in the example, it is [3].

Any help is appreciated. Thanks.

@Suba95 ,

hmmm…

lis = IN[0]
i = 0

OUT = []

for x in lis:
    if x <= i:
        OUT.append(x+1)
    else:
        OUT.append(x)

Is that what are you looking for? you want to avoid “emty” lists?

Hi,

May be, the way I questioned is not correct.

So, I have a list (that may contain multiple items - no static value). From that list, I want to extract the item at index 0, and run the dynamo script. After, finishing the index 0, I want to repeat the steps for other items in the list. As far as I know, dynamo will automatically check the whole list. But, in my case, the analysis contains user input, so each item in the list should run separately. Its a kind of iterating through lists. So, I though using while loop may help.

Thanks

You won’t be able to inject any user interaction between items within a single list. The whole node will have to execute before anything else can be done. You might be able to determine this interaction before running the node. We’d need more information on exactly what you’re trying to do.

1 Like

Hi,

I think the graph below will explain what exactly I need.

Here ‘get item at index 0’ is used, but I want to repeat the steps for all items in the list individually.

Thanks

Based on what you’ve shown I think you can just let Dynamo handle the iterating itself. If you’re not doing anything different at each index then it’s the same process every time. You just have to handle the list structure.

Your original workflow:

Using proper list management:

Hi,

Yes, I will organise the list structure and try this way.

In addition, are there any options available to request dynamo to go step by step? I am concerned because, in the end, the user will be selecting a material of their choice, and so I don’t want to create confusion by providing them with multiple material types at the same time. If it was one material, the user can track its properties easily and make selections promptly.

So, it will be beneficial if the dynamo can do the first index, and then go the next until it reaches the given limit.

That was the reason why I wanted to try looping, but unfortunately it didn’t work.

As Nick_Boyts says, it’ll go through the entire list.

You can, however, output the results of each output.

Maybe run the whole list but then use Datashapes to let the user select which material and only display the outputs relating to their selection?

Exactly what @Alien said. There’s no need to assign the material at each index. You can query them all first. Return the options. Then make the selections all at once.

I’ll also second the suggestion for Data-Shapes. It will make this all 100x easier and probably make more sense in the long run too.

Thanks, both for your suggestions. I will try to bring in Data-shapes nodes to get the desired result.

Hi,
I am trying to do a bit in sorting lists based on given conditions, before moving to the next step.

Here is the problem, I have a nested list with four levels. And I am trying to filter the list @L2 based on sub-list values @L1 - index [17]. I tried using basic sorting, and the attached python code, but unfortunately this is not helping me.

Any suggestions on this, please?

Thanks.

Two options (I think)…

Flatten the list before feeding it in…

OR

Nest the list in python… so for eg.

for thing in things:
    for ing in thing: 
        do thing here (that will look at the next level of your list.)

Don’t forget to deal with those Empty Lists. You can pull a value that doesn’t exist.