Skip to content

Instantly share code, notes, and snippets.

@nessita
nessita / one.py
Last active August 29, 2015 13:56 — forked from mgaitan/one.py
def one(iterable):
"""Return the object in the given iterable that evaluates to True.
If the given iterable has more than one object that evaluates to True,
or if there is no object that fulfills such condition, return None.
>>> one((True, False, False))
True
>>> one((True, False, True))
>>> one((0, 0, 'a'))