mirror of https://github.com/python/cpython
Revised the itertools quantifier recipes to match the performance of the
new builtins.
This commit is contained in:
parent
96229b1918
commit
f77d0334f3
|
@ -461,26 +461,26 @@ def nth(iterable, n):
|
||||||
"Returns the nth item"
|
"Returns the nth item"
|
||||||
return list(islice(iterable, n, n+1))
|
return list(islice(iterable, n, n+1))
|
||||||
|
|
||||||
def all(seq, pred=bool):
|
def all(seq, pred=None):
|
||||||
"Returns True if pred(x) is True for every element in the iterable"
|
"Returns True if pred(x) is true for every element in the iterable"
|
||||||
for elem in ifilterfalse(pred, seq):
|
for elem in ifilterfalse(pred, seq):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def any(seq, pred=bool):
|
def any(seq, pred=None):
|
||||||
"Returns True if pred(x) is True for at least one element in the iterable"
|
"Returns True if pred(x) is true for at least one element in the iterable"
|
||||||
for elem in ifilter(pred, seq):
|
for elem in ifilter(pred, seq):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def no(seq, pred=bool):
|
def no(seq, pred=None):
|
||||||
"Returns True if pred(x) is False for every element in the iterable"
|
"Returns True if pred(x) is false for every element in the iterable"
|
||||||
for elem in ifilter(pred, seq):
|
for elem in ifilter(pred, seq):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def quantify(seq, pred=bool):
|
def quantify(seq, pred=None):
|
||||||
"Count how many times the predicate is True in the sequence"
|
"Count how many times the predicate is true in the sequence"
|
||||||
return sum(imap(pred, seq))
|
return sum(imap(pred, seq))
|
||||||
|
|
||||||
def padnone(seq):
|
def padnone(seq):
|
||||||
|
|
|
@ -799,26 +799,26 @@ Samuele
|
||||||
... "Returns the nth item"
|
... "Returns the nth item"
|
||||||
... return list(islice(iterable, n, n+1))
|
... return list(islice(iterable, n, n+1))
|
||||||
|
|
||||||
>>> def all(seq, pred=bool):
|
>>> def all(seq, pred=None):
|
||||||
... "Returns True if pred(x) is True for every element in the iterable"
|
... "Returns True if pred(x) is true for every element in the iterable"
|
||||||
... for elem in ifilterfalse(pred, seq):
|
... for elem in ifilterfalse(pred, seq):
|
||||||
... return False
|
... return False
|
||||||
... return True
|
... return True
|
||||||
|
|
||||||
>>> def any(seq, pred=bool):
|
>>> def any(seq, pred=None):
|
||||||
... "Returns True if pred(x) is True for at least one element in the iterable"
|
... "Returns True if pred(x) is true for at least one element in the iterable"
|
||||||
... for elem in ifilter(pred, seq):
|
... for elem in ifilter(pred, seq):
|
||||||
... return True
|
... return True
|
||||||
... return False
|
... return False
|
||||||
|
|
||||||
>>> def no(seq, pred=bool):
|
>>> def no(seq, pred=None):
|
||||||
... "Returns True if pred(x) is False for every element in the iterable"
|
... "Returns True if pred(x) is false for every element in the iterable"
|
||||||
... for elem in ifilter(pred, seq):
|
... for elem in ifilter(pred, seq):
|
||||||
... return False
|
... return False
|
||||||
... return True
|
... return True
|
||||||
|
|
||||||
>>> def quantify(seq, pred=bool):
|
>>> def quantify(seq, pred=None):
|
||||||
... "Count how many times the predicate is True in the sequence"
|
... "Count how many times the predicate is true in the sequence"
|
||||||
... return sum(imap(pred, seq))
|
... return sum(imap(pred, seq))
|
||||||
|
|
||||||
>>> def padnone(seq):
|
>>> def padnone(seq):
|
||||||
|
|
Loading…
Reference in New Issue