Advertisement
here2share

# every_combo_demo.py

May 2nd, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. # every_combo_demo.py
  2.  
  3. def permute(seq):
  4.     l = len(seq)
  5.     if l == 1: return [seq]
  6.     else:
  7.         res=[]
  8.         for i in range(len(seq)):
  9.             rest = seq[:i] + seq[i+1:]
  10.             for x in permute(rest):
  11.                 res.append(seq[i:i+1] + x)
  12.         res.sort()
  13.         return res
  14. seq = list("1234")
  15. thelist = permute(seq)
  16. thelist = [ ''.join(x) for x in thelist ]
  17. print thelist
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement