
Exit
(1, 2, 3) (1, 3, 2) (2, 1, 3) (2, 3, 1) (3, 1, 2) (3, 2, 1)
This generates! permutations if the length of the input sequence is n.
If you want to get permutations of length L, then implement it as follows.
# Program Python to print all
# permutations of a given length
from
itertools
import
permutations
# Get all permutations of length 2
# and length 2
perm
=
permutations ([
1
,
2
,
3
],
2
)
# Print the resulting permutations
for
i
in
list
(perm):
print
i
Exit
(1, 2) (1, 3) (2, 1) (2, 3) (3, 1) (3, 2)
This generates nCr * r! permutations if the length of the input sequence is n and the input parameter is r.

Exit
(1, 2) (1, 3) (2, 3)

Exit
(2, 1) (2, 3) (1, 3)

Exit
(1, 1) (1, 3) (1, 3)

Exit
(1, 1) (1, 2) (1, 3) (2, 2) (2, 3) (3, 3)
This article is courtesy of Raju Varshney . Please post comments if you find something wrong or if you would like to share more information on the topic under discussion