Advertisement
here2share

# all_permutations_by_length.py

May 13th, 2019
1,675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. # all_permutations_by_length.py
  2.  
  3. def permutations(l, n, str_a=''):
  4.     if len(str_a) == n:
  5.         print str_a
  6.     else:
  7.         for c in l:
  8.             permutations(l, n, str_a+c)
  9.  
  10. zzz = permutations("ABC", 3)
  11.  
  12. '''
  13. output...
  14.  
  15. AAA
  16. AAB
  17. AAC
  18. ABA
  19. ABB
  20. ABC
  21. ACA
  22. ACB
  23. ACC
  24. BAA
  25. BAB
  26. BAC
  27. BBA
  28. BBB
  29. BBC
  30. BCA
  31. BCB
  32. BCC
  33. CAA
  34. CAB
  35. CAC
  36. CBA
  37. CBB
  38. CBC
  39. CCA
  40. CCB
  41. CCC
  42. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement