summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-07-19 23:21:57 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-07-19 23:21:57 (GMT)
commit39e0eb766f02e18711d7eac9f948754a1ee569e3 (patch)
tree434853b0d4bc508925d85fc55a88f48b0357e587 /Doc
parentd648f64a530a77db93df89cc03306ef80b27ff4f (diff)
downloadcpython-39e0eb766f02e18711d7eac9f948754a1ee569e3.zip
cpython-39e0eb766f02e18711d7eac9f948754a1ee569e3.tar.gz
cpython-39e0eb766f02e18711d7eac9f948754a1ee569e3.tar.bz2
Fix compress() recipe in docs to use itertools.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/itertools.rst6
1 files changed, 3 insertions, 3 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index 9a3626f..d8c3331 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -698,9 +698,9 @@ which incur interpreter overhead.
def compress(data, selectors):
"compress('abcdef', [1,0,1,0,1,1]) --> a c e f"
- for d, s in izip(data, selectors):
- if s:
- yield d
+ decorated = izip(data, selectors)
+ filtered = ifilter(operator.itemgetter(1), decorated)
+ return imap(operator.itemgetter(0), filtered)
def combinations_with_replacement(iterable, r):
"combinations_with_replacement('ABC', 3) --> AA AB AC BB BC CC"