Advertisement
j0h

itterations

j0h
Jul 31st, 2023
1,190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. import itertools
  2.  
  3. # Example 1: Permutations of a list
  4. my_list = [1, 2, 3]
  5. permutations_list = list(itertools.permutations(my_list))
  6.  
  7. print(permutations_list)
  8. # Output: [(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
  9.  
  10. # Example 2: Permutations of a string
  11. my_string = "abc"
  12. permutations_string = list(itertools.permutations(my_string))
  13.  
  14. print(permutations_string)
  15. # Output: [('a', 'b', 'c'), ('a', 'c', 'b'), ('b', 'a', 'c'), ('b', 'c', 'a'), ('c', 'a', 'b'), ('c', 'b', 'a')]
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement