summaryrefslogtreecommitdiffstats
path: root/Doc/library/itertools.rst
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-07-30 07:37:37 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-07-30 07:37:37 (GMT)
commitf5a2e47ad3bd5ada7d751625c208e65103116f93 (patch)
treeab8b4d9c0050044db737e67e17ae1f3b10f9785e /Doc/library/itertools.rst
parentfbf66bd61705624f8c5b4b68061eeb9e5296a871 (diff)
downloadcpython-f5a2e47ad3bd5ada7d751625c208e65103116f93.zip
cpython-f5a2e47ad3bd5ada7d751625c208e65103116f93.tar.gz
cpython-f5a2e47ad3bd5ada7d751625c208e65103116f93.tar.bz2
Neaten-up the itertools recipes.
Diffstat (limited to 'Doc/library/itertools.rst')
-rw-r--r--Doc/library/itertools.rst10
1 files changed, 4 insertions, 6 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index 79a69ea..7186443 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -563,12 +563,12 @@ which incur interpreter overhead.
return zip(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
return zip_longest(*args, fillvalue=fillvalue)
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)
@@ -588,10 +588,8 @@ which incur interpreter overhead.
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 = zip(data, selectors)
- filtered = filter(operator.itemgetter(1), decorated)
- return map(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"