For example, if the input is [1,2], then it returns [1,2] and [2,1].
import itertools lst = [1, 2, 3] print(list(itertools.permutations(lst)))
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
import itertools def get_permutations(lst): return ([list(permutation) for permutation in itertools.permutations(lst)]) print(get_permutations([1,2,3]))
[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
Help @MichaelDelgado spread the word by sharing this article on Twitter...