mirror of https://github.com/python/cpython
Add recipe to docs.
This commit is contained in:
parent
0098c9d609
commit
e8b4b60555
|
@ -692,3 +692,8 @@ which incur interpreter overhead. ::
|
|||
for n in xrange(2**len(pairs)):
|
||||
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"
|
||||
for d, s in izip(data, selectors):
|
||||
if s:
|
||||
yield d
|
||||
|
|
|
@ -1279,6 +1279,12 @@ Samuele
|
|||
... for n in xrange(2**len(pairs)):
|
||||
... 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"
|
||||
... for d, s in izip(data, selectors):
|
||||
... if s:
|
||||
... yield d
|
||||
|
||||
This is not part of the examples but it tests to make sure the definitions
|
||||
perform as purported.
|
||||
|
||||
|
@ -1353,6 +1359,9 @@ False
|
|||
>>> map(sorted, powerset('ab'))
|
||||
[[], ['a'], ['b'], ['a', 'b']]
|
||||
|
||||
>>> list(compress('abcdef', [1,0,1,0,1,1]))
|
||||
['a', 'c', 'e', 'f']
|
||||
|
||||
"""
|
||||
|
||||
__test__ = {'libreftest' : libreftest}
|
||||
|
|
Loading…
Reference in New Issue