Write a Python program to generate all permutations of a list in Python


This program imports the "itertools" module and uses the "permutations" function from itertools to find all possible permutations of the list [1,2,3]. The permutations function takes a single iterable as an argument and returns an iterator of tuples containing all possible permutations. In this case, the list [1,2,3] is passed as an argument to the permutations function, and the output will be an iterator of tuples containing all possible permutations of that list. The result is converted to a list using the list() function and printed on the console.

Source Code

import itertools
print(list(itertools.permutations([1,2,3])))
 

Output

[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]

Example Programs