fork download
  1. all = []
  2.  
  3. def gen(A, idx = 0, cur = []):
  4. if idx >= len(A):
  5. if len(cur): all.append(cur)
  6. return
  7.  
  8. gen(A, idx + 1, list(cur))
  9. incl = list(cur)
  10. incl.append(A[idx])
  11. gen(A, idx + 1, incl)
  12.  
  13. def solve(A):
  14. global all
  15. all = []
  16. gen(A)
  17. return all
  18.  
  19. print(solve([1, 4, 6]))
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
[[6], [4], [4, 6], [1], [1, 6], [1, 4], [1, 4, 6]]