mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
Fix compress() recipe in docs to use itertools.
This commit is contained in:
parent
d648f64a53
commit
39e0eb766f
2 changed files with 6 additions and 6 deletions
|
|
@ -698,9 +698,9 @@ which incur interpreter overhead.
|
||||||
|
|
||||||
def compress(data, selectors):
|
def compress(data, selectors):
|
||||||
"compress('abcdef', [1,0,1,0,1,1]) --> a c e f"
|
"compress('abcdef', [1,0,1,0,1,1]) --> a c e f"
|
||||||
for d, s in izip(data, selectors):
|
decorated = izip(data, selectors)
|
||||||
if s:
|
filtered = ifilter(operator.itemgetter(1), decorated)
|
||||||
yield d
|
return imap(operator.itemgetter(0), filtered)
|
||||||
|
|
||||||
def combinations_with_replacement(iterable, r):
|
def combinations_with_replacement(iterable, r):
|
||||||
"combinations_with_replacement('ABC', 3) --> AA AB AC BB BC CC"
|
"combinations_with_replacement('ABC', 3) --> AA AB AC BB BC CC"
|
||||||
|
|
|
||||||
|
|
@ -1281,9 +1281,9 @@ Samuele
|
||||||
|
|
||||||
>>> def compress(data, selectors):
|
>>> def compress(data, selectors):
|
||||||
... "compress('abcdef', [1,0,1,0,1,1]) --> a c e f"
|
... "compress('abcdef', [1,0,1,0,1,1]) --> a c e f"
|
||||||
... for d, s in izip(data, selectors):
|
... decorated = izip(data, selectors)
|
||||||
... if s:
|
... filtered = ifilter(operator.itemgetter(1), decorated)
|
||||||
... yield d
|
... return imap(operator.itemgetter(0), filtered)
|
||||||
|
|
||||||
>>> def combinations_with_replacement(iterable, r):
|
>>> def combinations_with_replacement(iterable, r):
|
||||||
... "combinations_with_replacement('ABC', 3) --> AA AB AC BB BC CC"
|
... "combinations_with_replacement('ABC', 3) --> AA AB AC BB BC CC"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue