Python Tip #4 - Find an element in a list satisfying condition

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

# 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.