diff --git a/Doc/lib/libitertools.tex b/Doc/lib/libitertools.tex index df73561ceb6..be53015f7cd 100644 --- a/Doc/lib/libitertools.tex +++ b/Doc/lib/libitertools.tex @@ -458,15 +458,21 @@ def nth(iterable, n): def all(seq, pred=bool): "Returns True if pred(x) is True for every element in the iterable" - return False not in imap(pred, seq) + for elem in ifilterfalse(pred, seq): + return False + return True def any(seq, pred=bool): - "Returns True if pred(x) is True at least one element in the iterable" - return True in imap(pred, seq) + "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" - return True not in imap(pred, seq) + 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" diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index e4c29ad33b3..6ce758a99eb 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -746,15 +746,21 @@ Samuele >>> def all(seq, pred=bool): ... "Returns True if pred(x) is True for every element in the iterable" -... return False not in imap(pred, seq) +... 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" -... return True in imap(pred, seq) +... 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" -... return True not in imap(pred, seq) +... 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"