>> A=[2,5,7];perms(A)
ans =
7 5 2
7 2 5
5 7 2
5 2 7
2 7 5
2 5 7
>> perms(1:4)
ans =
4 3 2 1
4 3 1 2
4 2 3 1
4 2 1 3
4 1 3 2
4 1 2 3
3 4 2 1
3 4 1 2
3 2 4 1
3 2 1 4
3 1 4 2
3 1 2 4
2 4 3 1
2 4 1 3
2 3 4 1
2 3 1 4
2 1 4 3
2 1 3 4
1 4 3 2
1 4 2 3
1 3 4 2
1 3 2 4
1 2 4 3
1 2 3 4
# -*- coding: utf-8 -*- import itertools print(list(itertools.permutations([0, 1, 2],3)))