From: Raymond Hettinger Date: Sat, 23 Feb 2008 10:04:15 +0000 (+0000) Subject: Add recipe using itertools.product(). X-Git-Tag: v2.6a1~109 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7832d4d534ff7105a0253694db734d5007b62e91;p=thirdparty%2FPython%2Fcpython.git Add recipe using itertools.product(). --- diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 7d1ec9664056..5cc3e08fa826 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -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) +