What if you want to find the first item that matches the condition instead of getting a list of items?
selected = None for i in items: if condition: selected = i break # Simpler version using next() selected = next((i for i in items if condition), None)
next() is a built in function which is not that well known.