fork download
  1. def func():
  2. def display(level):
  3. for i in range(1, level+1):
  4. print(stack[i], end = " ")
  5. print()
  6.  
  7. def subsets(level):
  8. if level <= n:
  9. for i in range(stack[level-1]+1,n+1):
  10. stack[level] = i
  11. display(level)
  12. subsets(level+1)
  13.  
  14. n = 3
  15.  
  16. stack = [0] * (n+1)
  17.  
  18. subsets(1)
  19.  
  20. func()
  21.  
  22.  
Success #stdin #stdout 0.04s 9496KB
stdin
3
stdout
1 
1 2 
1 2 3 
1 3 
2 
2 3 
3