fork download
  1. from itertools import chain, combinations
  2.  
  3. def powerset(s):
  4. "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
  5. return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
  6.  
  7. for result in powerset(range(3)):
  8. print(result)
Success #stdin #stdout 0.02s 9208KB
stdin
Standard input is empty
stdout
()
(0,)
(1,)
(2,)
(0, 1)
(0, 2)
(1, 2)
(0, 1, 2)