Faster implementations for all/any.

This commit is contained in:
Jeremy Fincher 2003-10-11 03:20:51 +00:00
parent 701380de7c
commit 5e3c5fc703

View File

@ -107,20 +107,16 @@ def partition(p, L):
def any(p, seq): def any(p, seq):
"""Returns true if any element in seq satisfies predicate p.""" """Returns true if any element in seq satisfies predicate p."""
if p is None: for elt in itertools.ifilter(p, seq):
p = bool
for elt in seq:
if p(elt):
return True return True
else:
return False return False
def all(p, seq): def all(p, seq):
"""Returns true if all elements in seq satisfy predicate p.""" """Returns true if all elements in seq satisfy predicate p."""
if p is None: for elt in itertools.ifilterfalse(p, seq):
p = bool
for elt in seq:
if not p(elt):
return False return False
else:
return True return True
def rsplit(s, sep=None, maxsplit=-1): def rsplit(s, sep=None, maxsplit=-1):