Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. def permutation(s):
  2. if len(s) == 1:
  3. return [s]
  4.  
  5. perm_list = [] # resulting list
  6. for a in s:
  7. remaining_elements = [x for x in s if x != a]
  8. z = permutation(remaining_elements) # permutations of sublist
  9.  
  10. for t in z:
  11. perm_list.append([a] + t)
  12.  
  13. return perm_list
  14.  
  15. print(permutation("123456789"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement