Skip to content

Instantly share code, notes, and snippets.

@facundobatista
facundobatista / one.py
Last active August 29, 2015 13:56 — forked from mgaitan/one.py
def one(iterable):
"""
Return X if X is the only one value where bool(i) is True for
each every i in the iterable. In any other case return None.
>>> one((True, False, False))
True
>>> one((True, False, True))
False
>>> one((0, 0, 'a'))