Add recipe using itertools.product().

This commit is contained in:
Raymond Hettinger 2008-02-23 10:04:15 +00:00
parent 532316dfa6
commit 7832d4d534
1 changed files with 6 additions and 0 deletions

View File

@ -559,3 +559,9 @@ which incur interpreter overhead. ::
pending -= 1
nexts = cycle(islice(nexts, pending))
def powerset(iterable):
"powerset('ab') --> set([]), set(['b']), set(['a']), set(['a', 'b'])"
skip = object()
for t in product(*izip(repeat(skip), iterable)):
yield set(e for e in t if e is not skip)