How to generate all possible permutations of a list with specific length of N in Python

1 Answer

0 votes
import itertools

lst = [1, 2, 3]

permutations = list(itertools.permutations(lst, r = 2))

print(permutations)





'''
run:

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

'''

 



answered Apr 20, 2021 by avibootz
...