March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
26
Task/Power-set/Python/power-set-5.py
Normal file
26
Task/Power-set/Python/power-set-5.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
>>> from pprint import pprint as pp
|
||||
>>> from itertools import chain, combinations
|
||||
>>>
|
||||
>>> def powerset(iterable):
|
||||
"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))
|
||||
|
||||
>>> pp(set(powerset({1,2,3,4})))
|
||||
{(),
|
||||
(1,),
|
||||
(1, 2),
|
||||
(1, 2, 3),
|
||||
(1, 2, 3, 4),
|
||||
(1, 2, 4),
|
||||
(1, 3),
|
||||
(1, 3, 4),
|
||||
(1, 4),
|
||||
(2,),
|
||||
(2, 3),
|
||||
(2, 3, 4),
|
||||
(2, 4),
|
||||
(3,),
|
||||
(3, 4),
|
||||
(4,)}
|
||||
>>>
|
||||
Loading…
Add table
Add a link
Reference in a new issue