summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-07-30 07:27:30 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-07-30 07:27:30 (GMT)
commitefdf706a9fb20da82d8b600cce47a3fafb490571 (patch)
treef9844b8c8d511d30881818f81858de998c7bfefe /Lib
parent66b14de7bbea8659fb8344d250662eae5ed9d820 (diff)
downloadcpython-efdf706a9fb20da82d8b600cce47a3fafb490571.zip
cpython-efdf706a9fb20da82d8b600cce47a3fafb490571.tar.gz
cpython-efdf706a9fb20da82d8b600cce47a3fafb490571.tar.bz2
Neaten-up the itertools recipes.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_itertools.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index 1a4e936..f6174ab 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -1234,13 +1234,13 @@ Samuele
... return izip(a, b)
>>> def grouper(n, iterable, fillvalue=None):
-... "grouper(3, 'abcdefg', 'x') --> ('a','b','c'), ('d','e','f'), ('g','x','x')"
+... "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
... args = [iter(iterable)] * n
... kwds = dict(fillvalue=fillvalue)
... return izip_longest(*args, **kwds)
>>> def roundrobin(*iterables):
-... "roundrobin('abc', 'd', 'ef') --> 'a', 'd', 'e', 'b', 'f', 'c'"
+... "roundrobin('ABC', 'D', 'EF') --> A D E B F C"
... # Recipe credited to George Sakkis
... pending = len(iterables)
... nexts = cycle(iter(it).next for it in iterables)
@@ -1260,10 +1260,8 @@ Samuele
... yield set(x for m, x in pairs if m&n)
>>> def compress(data, selectors):
-... "compress('abcdef', [1,0,1,0,1,1]) --> a c e f"
-... decorated = izip(data, selectors)
-... filtered = ifilter(operator.itemgetter(1), decorated)
-... return imap(operator.itemgetter(0), filtered)
+... "compress('ABCDEF', [1,0,1,0,1,1]) --> A C E F"
+... return (d for d, s in izip(data, selectors) if s)
>>> def combinations_with_replacement(iterable, r):
... "combinations_with_replacement('ABC', 3) --> AA AB AC BB BC CC"