Loop trough till find match

Hi! I am looking for a way to loop trough objects in list until I find a match. It is like this:


for obj in list:
    if obj in list2:
        if obj["prop"] == Ture:
            do further stuff...

So it must stop looping until there is found an object in list that is also in list2 and that has the property “prop” equal to True in it. How to achieve this?


for obj in list:
    if obj in list 2:
        if obj["prop"] == Ture:
            do stuff...
            break
        else:
            continue

Found this in Stack Overflow and it works great!:slight_smile:

stuff = [obj for obj in list if 'property_name' in obj]

Now the list stuff has all the objects with the property_name (list 2 not needed)

if it is only one object, use: stuff.

Else loop trough stuff to do stuff with all objects in that list:

for obj in stuff:
    #do what you want with the object
    if obj["prop"] == True:
        #do something with ur match