Add recipe to docs.
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index f546fe1..1f67739 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -692,3 +692,8 @@
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
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index 696fdeb..3b5cc23 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -1279,6 +1279,12 @@
... 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 @@
>>> map(sorted, powerset('ab'))
[[], ['a'], ['b'], ['a', 'b']]
+>>> list(compress('abcdef', [1,0,1,0,1,1]))
+['a', 'c', 'e', 'f']
+
"""
__test__ = {'libreftest' : libreftest}