mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
Add recipe to docs.
This commit is contained in:
parent
0098c9d609
commit
e8b4b60555
2 changed files with 14 additions and 0 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue