here2share

# z_fast_permute.py

Dec 21st, 2021 (edited)
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. # z_fast_permute.py
  2.  
  3. def permute(zzz):
  4.     if len(zzz) == 1:
  5.         return [zzz]
  6.     return [[zzz[i]] + p for i in range(len(zzz)) for p in permute(zzz[:i] + zzz [i+1:])]
  7.  
  8. for zzz in permute([1,2,3,4]):
  9.     print ''.join(str(z) for z in zzz),
  10.    
  11. '1234 1243 1324 1342 1423 1432 2134 2143 2314 2341 2413 2431 3124 3142 3214 3241 3412 3421 4123 4132 4213 4231 4312 4321'
Add Comment
Please, Sign In to add comment