[ python-Feature Requests-1432437 ] itertools.any and itertools.all
SourceForge.net
noreply at sourceforge.net
Wed Feb 15 21:44:30 CET 2006
Feature Requests item #1432437, was opened at 2006-02-15 21:26
Message generated for change (Comment added) made by birkenfeld
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: Closed
>Resolution: Out of Date
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))".
----------------------------------------------------------------------
>Comment By: Georg Brandl (birkenfeld)
Date: 2006-02-15 21:44
Message:
Logged In: YES
user_id=1188172
These two happen to become builtins in 2.5.
----------------------------------------------------------------------
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