Message54722
| Author |
paulcannon |
| Recipients |
| Date |
2006年02月15日.20:26:42 |
| SpamBayes Score |
| Marked as misclassified |
| Message-id |
| In-reply-to |
| Content |
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))".
|
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2007年08月23日 16:11:37 | admin | link | issue1432437 messages |
| 2007年08月23日 16:11:37 | admin | create |
|