Advertisement
furas

Python - permutation

Mar 15th, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. from itertools import permutations
  4.  
  5. #help(itertools.permutations)
  6.  
  7. # digits = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
  8. #digits = list(reversed(range(10)))
  9. digits = list(range(9, -1, -1))
  10.  
  11. for length in range(10, 0, -1):
  12.     for x in permutations(digits, length):
  13.         print(x)
  14.  
  15. # (9, 8, 7, 6, 5, 4, 3, 2, 1, 0)  # length 10
  16. # (9, 8, 7, 6, 5, 4, 3, 2, 0, 1)  # length 10
  17. # (9, 8, 7, 6, 5, 4, 3, 1, 2, 0)  # length 10
  18. # (9, 8, 7, 6, 5, 4, 3, 1, 0, 2)  # length 10
  19. # ... etc. ...
  20. # (3,)  # length 1
  21. # (2,)  # length 1
  22. # (1,)  # length 1
  23.  
  24. #--------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement