[ python-Feature Requests-1432437 ] itertools.any and itertools.all
SourceForge.net
noreply at sourceforge.net
Wed Feb 15 21:26:42 CET 2006
Feature Requests item #1432437, was opened at 2006-02-15 13:26
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1432437&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: paul cannon (paulcannon)
Assigned to: Nobody/Anonymous (nobody)
Summary: itertools.any and itertools.all
Initial Comment:
Just a couple very simple "shortcutting" functions that
I find myself needing quite frequently.
"reduce(operator.or_, foo, False)" is all right, but
potentially does a lot more work.
def any(i):
"""Returns true if any element from i is true."""
for element in i:
if i:
return True
return False
all() would also be nice:
def all(i):
"""Returns true if all elements from i are true."""
for element in i:
if not i:
return False
return True
..although it /could/ simply be built on any() as "not
any(imap(operator.not_, i))".
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1432437&group_id=5470
More information about the Python-bugs-list
mailing list