1# A Python program to print all permutations using library function
2from itertools import permutations
3perm = permutations([1, 2, 3])
4for i in list(perm):
5 print (i)
6# (1, 2, 3)
7# (1, 3, 2)
8# (2, 1, 3)
9# (2, 3, 1)
10# (3, 1, 2)
11# (3, 2, 1)
1import itertools
2
3a = [1, 2, 3]
4n = 3
5
6perm_iterator = itertools.permutations(a, n)
7
8for item in perm_iterator:
9 print(item)
1>>> from itertools import permutations
2>>> perms = [''.join(p) for p in permutations('stack')]
3>>> perms
4