[Python-checkins] r65149 - in python/trunk: Doc/library/itertools.rst Lib/test/test_itertools.py
raymond.hettinger
python-checkins at python.org
Sun Jul 20 01:21:58 CEST 2008
Author: raymond.hettinger
Date: Sun Jul 20 01:21:57 2008
New Revision: 65149
Log:
Fix compress() recipe in docs to use itertools.
Modified:
python/trunk/Doc/library/itertools.rst
python/trunk/Lib/test/test_itertools.py
Modified: python/trunk/Doc/library/itertools.rst
==============================================================================
--- python/trunk/Doc/library/itertools.rst (original)
+++ python/trunk/Doc/library/itertools.rst Sun Jul 20 01:21:57 2008
@@ -698,9 +698,9 @@
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"
Modified: python/trunk/Lib/test/test_itertools.py
==============================================================================
--- python/trunk/Lib/test/test_itertools.py (original)
+++ python/trunk/Lib/test/test_itertools.py Sun Jul 20 01:21:57 2008
@@ -1281,9 +1281,9 @@
>>> 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"
More information about the Python-checkins
mailing list