How to generate all permutations of 1, 2 and 3 without repetition in Python

1 Answer

0 votes
from itertools import permutations

lst = list(permutations(range(1, 4)))

print(lst)

for i in range(len(lst)):
    print(lst[i])

   
   
     
'''
run:
     
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
(1, 2, 3)
(1, 3, 2)
(2, 1, 3)
(2, 3, 1)
(3, 1, 2)
(3, 2, 1)

'''

 



answered Oct 1, 2021 by avibootz
...