Advertisement
here2share

# combos_fullscale.py

Nov 18th, 2019
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. # combos_fullscale.py
  2.  
  3. def combos(data,n):
  4.     if not n:
  5.         return [[]]
  6.     d=[]
  7.     for i in range(0,len(data)):
  8.         m=data[i]
  9.         remdata=data[i+1:]
  10.         for p in combos(remdata,n-1):
  11.             d.append([m]+p)
  12.     return d
  13.  
  14. def combos_fullscale(data):
  15.     d = []
  16.     for z in range(1,len(data)+1):
  17.         d.extend(combos(data, z))
  18.     return d
  19.  
  20. print combos_fullscale(["A","B","C"])
  21.  
  22. '''
  23. output...
  24.  
  25. [['A'], ['B'], ['C'], ['A', 'B'], ['A', 'C'], ['B', 'C'], ['A', 'B', 'C']]
  26. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement