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
... 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.
>>> map(sorted, powerset('ab'))
[[], ['a'], ['b'], ['a', 'b']]
+>>> list(compress('abcdef', [1,0,1,0,1,1]))
+['a', 'c', 'e', 'f']
+
"""
__test__ = {'libreftest' : libreftest}