diff options
author | Raymond Hettinger <python@rcn.com> | 2004-09-23 07:27:39 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-09-23 07:27:39 (GMT) |
commit | 4533f1fb7fbf1fa8a9cb264ff6f1f0aba043e80d (patch) | |
tree | d3a1460e3d46dc7ea42c6c0069a2d963949a4cff /Doc/lib | |
parent | 513c8bd6f2523f5c6bf7e99996d65691c5e36013 (diff) | |
download | cpython-4533f1fb7fbf1fa8a9cb264ff6f1f0aba043e80d.zip cpython-4533f1fb7fbf1fa8a9cb264ff6f1f0aba043e80d.tar.gz cpython-4533f1fb7fbf1fa8a9cb264ff6f1f0aba043e80d.tar.bz2 |
Improve three recipes in the itertools docs.
Diffstat (limited to 'Doc/lib')
-rw-r--r-- | Doc/lib/libitertools.tex | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Doc/lib/libitertools.tex b/Doc/lib/libitertools.tex index df73561..be53015 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" |