fork download
  1. def subsets():
  2. def solve(n):
  3. k = 2 ** n
  4. out = [{}]
  5. for i in range(1, k):
  6. s = []
  7. for j in range(0, n):
  8. if i & (1<<j):
  9. s.append(j+1)
  10. out.append(s)
  11.  
  12. working_set = list(map(lambda x: set(x), out))
  13.  
  14. for element in working_set:
  15.  
  16. print(element)
  17. n = 3
  18. solve(n)
  19. subsets()
  20.  
Success #stdin #stdout 0.03s 9660KB
stdin
Standard input is empty
stdout
set()
{1}
{2}
{1, 2}
{3}
{1, 3}
{2, 3}
{1, 2, 3}