Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools
- # Example 1: Permutations of a list
- my_list = [1, 2, 3]
- permutations_list = list(itertools.permutations(my_list))
- print(permutations_list)
- # Output: [(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
- # Example 2: Permutations of a string
- my_string = "abc"
- permutations_string = list(itertools.permutations(my_string))
- print(permutations_string)
- # Output: [('a', 'b', 'c'), ('a', 'c', 'b'), ('b', 'a', 'c'), ('b', 'c', 'a'), ('c', 'a', 'b'), ('c', 'b', 'a')]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement