From: Raymond Hettinger Date: Fri, 11 Mar 2005 22:17:30 +0000 (+0000) Subject: Revised the itertools quantifier recipes to match the performance of the X-Git-Tag: v2.5a0~1930 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f77d0334f30e331f005090723cd1d2955959a8cd;p=python Revised the itertools quantifier recipes to match the performance of the new builtins. --- diff --git a/Doc/lib/libitertools.tex b/Doc/lib/libitertools.tex index fbde69dad1..780ed55023 100644 --- a/Doc/lib/libitertools.tex +++ b/Doc/lib/libitertools.tex @@ -461,26 +461,26 @@ def nth(iterable, n): "Returns the nth item" return list(islice(iterable, n, n+1)) -def all(seq, pred=bool): - "Returns True if pred(x) is True for every element in the iterable" +def all(seq, pred=None): + "Returns True if pred(x) is true for every element in the iterable" for elem in ifilterfalse(pred, seq): return False return True -def any(seq, pred=bool): - "Returns True if pred(x) is True for at least one element in the iterable" +def any(seq, pred=None): + "Returns True if pred(x) is true for at least one element in the iterable" for elem in ifilter(pred, seq): return True return False -def no(seq, pred=bool): - "Returns True if pred(x) is False for every element in the iterable" +def no(seq, pred=None): + "Returns True if pred(x) is false for every element in the iterable" for elem in ifilter(pred, seq): return False return True -def quantify(seq, pred=bool): - "Count how many times the predicate is True in the sequence" +def quantify(seq, pred=None): + "Count how many times the predicate is true in the sequence" return sum(imap(pred, seq)) def padnone(seq): diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index becb3b2088..577082bd39 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -799,26 +799,26 @@ Samuele ... "Returns the nth item" ... return list(islice(iterable, n, n+1)) ->>> def all(seq, pred=bool): -... "Returns True if pred(x) is True for every element in the iterable" +>>> def all(seq, pred=None): +... "Returns True if pred(x) is true for every element in the iterable" ... for elem in ifilterfalse(pred, seq): ... return False ... return True ->>> def any(seq, pred=bool): -... "Returns True if pred(x) is True for at least one element in the iterable" +>>> def any(seq, pred=None): +... "Returns True if pred(x) is true for at least one element in the iterable" ... for elem in ifilter(pred, seq): ... return True ... return False ->>> def no(seq, pred=bool): -... "Returns True if pred(x) is False for every element in the iterable" +>>> def no(seq, pred=None): +... "Returns True if pred(x) is false for every element in the iterable" ... for elem in ifilter(pred, seq): ... return False ... return True ->>> def quantify(seq, pred=bool): -... "Count how many times the predicate is True in the sequence" +>>> def quantify(seq, pred=None): +... "Count how many times the predicate is true in the sequence" ... return sum(imap(pred, seq)) >>> def padnone(seq):