Advertisement
here2share

# permutate.py

Jul 8th, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.23 KB | None | 0 0
  1. # permutate.py
  2. def perm(z):
  3.     if type(z) == type(''):
  4.         z=list(z)
  5.     sz = len(z)
  6.     if sz <= 1:
  7.         return [z]
  8.     return [p[:i]+[z[0]]+p[i:] for i in range(sz) for p in perm(z[1:])]
  9.  
  10. print perm('abcd')
  11. print
  12. print perm([1,2,3,4])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement