I've got a list, which may or may not contain a unique element satisfying a given predicate. I am looking for an expression which evaluates to an item satisfying that predicate if it exists and is unique, and otherwise returns None. Something like
numbers = [4, 3, 9, 7, 1, 2, 8]
print(the(item for item in numbers if item > 10)) # None
print(the(item for item in numbers if item % 2 == 0)) # None
print(the(item for item in numbers if item % 7 == 0)) # 7
Is there a built-in idiom for this, or do I have to write my own the function?