made power set return lists for ease of usage

This commit is contained in:
Shay Nehmad 2019-08-11 17:49:24 +03:00
parent e500068e45
commit 547067c4da
2 changed files with 9 additions and 9 deletions

View File

@ -6,4 +6,4 @@ def power_set(iterable):
https://docs.python.org/3/library/itertools.html#itertools-recipes
"""
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in range(1, len(s) + 1))
return [list(x) for x in list(chain.from_iterable(combinations(s, r) for r in range(1, len(s) + 1)))]

View File

@ -5,14 +5,14 @@ class TestPower_set(TestCase):
def test_power_set(self):
before = ('a', 'b', 'c')
after_expected = [
('a', ),
('b',),
('c',),
('a', 'b'),
('a', 'c'),
('b', 'c'),
('a', 'b', 'c'),
['a'],
['b'],
['c'],
['a', 'b'],
['a', 'c'],
['b', 'c'],
['a', 'b', 'c'],
]
from common.utils.itertools_extensions import power_set
self.assertEquals(list(power_set(before)), after_expected)
self.assertEquals(power_set(before), after_expected)