Get the index of a list from the comparison of two lists with Python

Hello community,
I’m just starting to learn Python and I know I can do this with Dynamo, but I want to put it into practice by improving my scripts with python.
The issue is the following, I generated a code in python to compare two lists and that gives me the index of the items that are used in list one according to the order of list 2, the code works fine in the Python IDLE but when placing it in the Dynamo node it gives me a single value.

l1 = IN[0]
l2 = IN[1]

for indice, (item1) in enumerate(l1):
    for indice, (item2) in enumerate(l2):
        if item1 == item2:
            print(indice)
       
OUT=indice

Right now it’s just outputting the last index that was used in the loop. You’d need to append each value to a new list and then output the list.

2 Likes

The reason it returns a single value in dynamo but not in python is because it is only returning the final value of “indice” during the last loop. When using it in python. You are printing the indice every time it loops. But what you want is to return a list. Not a single indice value. Create an empty list and instead of printing append indice to the list during each loop.

1 Like

Lol zachri and I on the mind meld tonight :joy:

Thanks @mzjensen and @WrightEngineering :smiley:

1 Like