summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_itertools.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-01-26 02:23:50 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-01-26 02:23:50 (GMT)
commitace673391acbe0411b20b972b6068dab7a0bbdb4 (patch)
treeb6483acf551bb28b1fd230ff0cd1188048c0cc52 /Lib/test/test_itertools.py
parent89e12963ad7f0551b325b282267ad21011aa5fd7 (diff)
downloadcpython-ace673391acbe0411b20b972b6068dab7a0bbdb4.zip
cpython-ace673391acbe0411b20b972b6068dab7a0bbdb4.tar.gz
cpython-ace673391acbe0411b20b972b6068dab7a0bbdb4.tar.bz2
Backport r68942: update powerset() recipe.
Diffstat (limited to 'Lib/test/test_itertools.py')
-rw-r--r--Lib/test/test_itertools.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index ba55d23..7023b29 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -1277,11 +1277,9 @@ Samuele
... nexts = cycle(islice(nexts, pending))
>>> def powerset(iterable):
-... "powerset('ab') --> set([]), set(['a']), set(['b']), set(['a', 'b'])"
-... # Recipe credited to Eric Raymond
-... pairs = [(2**i, x) for i, x in enumerate(iterable)]
-... for n in range(2**len(pairs)):
-... yield set(x for m, x in pairs if m&n)
+... "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
+... s = list(iterable)
+... return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
>>> def compress(data, selectors):
... "compress('ABCDEF', [1,0,1,0,1,1]) --> A C E F"
@@ -1379,8 +1377,8 @@ perform as purported.
>>> list(roundrobin('abc', 'd', 'ef'))
['a', 'd', 'e', 'b', 'f', 'c']
->>> list(map(sorted, powerset('ab')))
-[[], ['a'], ['b'], ['a', 'b']]
+>>> list(powerset([1,2,3]))
+[(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]
>>> list(compress('abcdef', [1,0,1,0,1,1]))
['a', 'c', 'e', 'f']