]> granicus.if.org Git - python/commitdiff
Add recipe using itertools.product().
authorRaymond Hettinger <python@rcn.com>
Sat, 23 Feb 2008 10:04:15 +0000 (10:04 +0000)
committerRaymond Hettinger <python@rcn.com>
Sat, 23 Feb 2008 10:04:15 +0000 (10:04 +0000)
Doc/library/itertools.rst

index 7d1ec9664056385bd7df091a895399a7404f38b3..5cc3e08fa826afb934b6f855640c25ecff13d912 100644 (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)
+