From 7832d4d534ff7105a0253694db734d5007b62e91 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sat, 23 Feb 2008 10:04:15 +0000 Subject: [PATCH] Add recipe using itertools.product(). --- Doc/library/itertools.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 7d1ec966405..5cc3e08fa82 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) +