-3

想象一下有这个列表

[[1,2,3],[1,2,3],[1,2,3]]

如何获得这些排列:

[[1,2,3],[1,2,3],[1,2,3]]
[[1,2,3],[1,2,3],[1,3,2]]
[[1,2,3],[1,2,3],[2,1,3]]
[[1,2,3],[1,2,3],[2,3,1]]
....
[[1,2,3],[1,3,2],[1,2,3]]
[[1,2,3],[1,3,2],[1,3,2]]
[[1,2,3],[1,3,2],[2,1,3]]
....
[[3,2,1],[3,2,1],[3,2,1]]
4

1 回答 1

0
import itertools
seq = [[1,2,3], [1,2,3], [1,2,3]]
for item in itertools.product(*[itertools.permutations(sublist) for sublist in seq]):
    print item

结果:

((1, 2, 3), (1, 2, 3), (1, 2, 3))
((1, 2, 3), (1, 2, 3), (1, 3, 2))
((1, 2, 3), (1, 2, 3), (2, 1, 3))
((1, 2, 3), (1, 2, 3), (2, 3, 1))
((1, 2, 3), (1, 2, 3), (3, 1, 2))
((1, 2, 3), (1, 2, 3), (3, 2, 1))
((1, 2, 3), (1, 3, 2), (1, 2, 3))
((1, 2, 3), (1, 3, 2), (1, 3, 2))
((1, 2, 3), (1, 3, 2), (2, 1, 3))
((1, 2, 3), (1, 3, 2), (2, 3, 1))
((1, 2, 3), (1, 3, 2), (3, 1, 2))
((1, 2, 3), (1, 3, 2), (3, 2, 1))
((1, 2, 3), (2, 1, 3), (1, 2, 3))
((1, 2, 3), (2, 1, 3), (1, 3, 2))
((1, 2, 3), (2, 1, 3), (2, 1, 3))
((1, 2, 3), (2, 1, 3), (2, 3, 1))
((1, 2, 3), (2, 1, 3), (3, 1, 2))
((1, 2, 3), (2, 1, 3), (3, 2, 1))
((1, 2, 3), (2, 3, 1), (1, 2, 3))
((1, 2, 3), (2, 3, 1), (1, 3, 2))
((1, 2, 3), (2, 3, 1), (2, 1, 3))
((1, 2, 3), (2, 3, 1), (2, 3, 1))
((1, 2, 3), (2, 3, 1), (3, 1, 2))
((1, 2, 3), (2, 3, 1), (3, 2, 1))
((1, 2, 3), (3, 1, 2), (1, 2, 3))
((1, 2, 3), (3, 1, 2), (1, 3, 2))
((1, 2, 3), (3, 1, 2), (2, 1, 3))
((1, 2, 3), (3, 1, 2), (2, 3, 1))
((1, 2, 3), (3, 1, 2), (3, 1, 2))
((1, 2, 3), (3, 1, 2), (3, 2, 1))
((1, 2, 3), (3, 2, 1), (1, 2, 3))
((1, 2, 3), (3, 2, 1), (1, 3, 2))
((1, 2, 3), (3, 2, 1), (2, 1, 3))
((1, 2, 3), (3, 2, 1), (2, 3, 1))
((1, 2, 3), (3, 2, 1), (3, 1, 2))
((1, 2, 3), (3, 2, 1), (3, 2, 1))
((1, 3, 2), (1, 2, 3), (1, 2, 3))
((1, 3, 2), (1, 2, 3), (1, 3, 2))
((1, 3, 2), (1, 2, 3), (2, 1, 3))
((1, 3, 2), (1, 2, 3), (2, 3, 1))
((1, 3, 2), (1, 2, 3), (3, 1, 2))
((1, 3, 2), (1, 2, 3), (3, 2, 1))
((1, 3, 2), (1, 3, 2), (1, 2, 3))
((1, 3, 2), (1, 3, 2), (1, 3, 2))
((1, 3, 2), (1, 3, 2), (2, 1, 3))
((1, 3, 2), (1, 3, 2), (2, 3, 1))
((1, 3, 2), (1, 3, 2), (3, 1, 2))
((1, 3, 2), (1, 3, 2), (3, 2, 1))
((1, 3, 2), (2, 1, 3), (1, 2, 3))
((1, 3, 2), (2, 1, 3), (1, 3, 2))
((1, 3, 2), (2, 1, 3), (2, 1, 3))
((1, 3, 2), (2, 1, 3), (2, 3, 1))
((1, 3, 2), (2, 1, 3), (3, 1, 2))
((1, 3, 2), (2, 1, 3), (3, 2, 1))
((1, 3, 2), (2, 3, 1), (1, 2, 3))
((1, 3, 2), (2, 3, 1), (1, 3, 2))
((1, 3, 2), (2, 3, 1), (2, 1, 3))
((1, 3, 2), (2, 3, 1), (2, 3, 1))
((1, 3, 2), (2, 3, 1), (3, 1, 2))
((1, 3, 2), (2, 3, 1), (3, 2, 1))
((1, 3, 2), (3, 1, 2), (1, 2, 3))
((1, 3, 2), (3, 1, 2), (1, 3, 2))
((1, 3, 2), (3, 1, 2), (2, 1, 3))
((1, 3, 2), (3, 1, 2), (2, 3, 1))
((1, 3, 2), (3, 1, 2), (3, 1, 2))
((1, 3, 2), (3, 1, 2), (3, 2, 1))
((1, 3, 2), (3, 2, 1), (1, 2, 3))
((1, 3, 2), (3, 2, 1), (1, 3, 2))
((1, 3, 2), (3, 2, 1), (2, 1, 3))
((1, 3, 2), (3, 2, 1), (2, 3, 1))
((1, 3, 2), (3, 2, 1), (3, 1, 2))
((1, 3, 2), (3, 2, 1), (3, 2, 1))
((2, 1, 3), (1, 2, 3), (1, 2, 3))
((2, 1, 3), (1, 2, 3), (1, 3, 2))
((2, 1, 3), (1, 2, 3), (2, 1, 3))
((2, 1, 3), (1, 2, 3), (2, 3, 1))
((2, 1, 3), (1, 2, 3), (3, 1, 2))
((2, 1, 3), (1, 2, 3), (3, 2, 1))
((2, 1, 3), (1, 3, 2), (1, 2, 3))
((2, 1, 3), (1, 3, 2), (1, 3, 2))
((2, 1, 3), (1, 3, 2), (2, 1, 3))
((2, 1, 3), (1, 3, 2), (2, 3, 1))
((2, 1, 3), (1, 3, 2), (3, 1, 2))
((2, 1, 3), (1, 3, 2), (3, 2, 1))
((2, 1, 3), (2, 1, 3), (1, 2, 3))
((2, 1, 3), (2, 1, 3), (1, 3, 2))
((2, 1, 3), (2, 1, 3), (2, 1, 3))
((2, 1, 3), (2, 1, 3), (2, 3, 1))
((2, 1, 3), (2, 1, 3), (3, 1, 2))
((2, 1, 3), (2, 1, 3), (3, 2, 1))
((2, 1, 3), (2, 3, 1), (1, 2, 3))
((2, 1, 3), (2, 3, 1), (1, 3, 2))
((2, 1, 3), (2, 3, 1), (2, 1, 3))
((2, 1, 3), (2, 3, 1), (2, 3, 1))
((2, 1, 3), (2, 3, 1), (3, 1, 2))
((2, 1, 3), (2, 3, 1), (3, 2, 1))
((2, 1, 3), (3, 1, 2), (1, 2, 3))
((2, 1, 3), (3, 1, 2), (1, 3, 2))
((2, 1, 3), (3, 1, 2), (2, 1, 3))
((2, 1, 3), (3, 1, 2), (2, 3, 1))
((2, 1, 3), (3, 1, 2), (3, 1, 2))
((2, 1, 3), (3, 1, 2), (3, 2, 1))
((2, 1, 3), (3, 2, 1), (1, 2, 3))
((2, 1, 3), (3, 2, 1), (1, 3, 2))
((2, 1, 3), (3, 2, 1), (2, 1, 3))
((2, 1, 3), (3, 2, 1), (2, 3, 1))
((2, 1, 3), (3, 2, 1), (3, 1, 2))
((2, 1, 3), (3, 2, 1), (3, 2, 1))
((2, 3, 1), (1, 2, 3), (1, 2, 3))
((2, 3, 1), (1, 2, 3), (1, 3, 2))
((2, 3, 1), (1, 2, 3), (2, 1, 3))
((2, 3, 1), (1, 2, 3), (2, 3, 1))
((2, 3, 1), (1, 2, 3), (3, 1, 2))
((2, 3, 1), (1, 2, 3), (3, 2, 1))
((2, 3, 1), (1, 3, 2), (1, 2, 3))
((2, 3, 1), (1, 3, 2), (1, 3, 2))
((2, 3, 1), (1, 3, 2), (2, 1, 3))
((2, 3, 1), (1, 3, 2), (2, 3, 1))
((2, 3, 1), (1, 3, 2), (3, 1, 2))
((2, 3, 1), (1, 3, 2), (3, 2, 1))
((2, 3, 1), (2, 1, 3), (1, 2, 3))
((2, 3, 1), (2, 1, 3), (1, 3, 2))
((2, 3, 1), (2, 1, 3), (2, 1, 3))
((2, 3, 1), (2, 1, 3), (2, 3, 1))
((2, 3, 1), (2, 1, 3), (3, 1, 2))
((2, 3, 1), (2, 1, 3), (3, 2, 1))
((2, 3, 1), (2, 3, 1), (1, 2, 3))
((2, 3, 1), (2, 3, 1), (1, 3, 2))
((2, 3, 1), (2, 3, 1), (2, 1, 3))
((2, 3, 1), (2, 3, 1), (2, 3, 1))
((2, 3, 1), (2, 3, 1), (3, 1, 2))
((2, 3, 1), (2, 3, 1), (3, 2, 1))
((2, 3, 1), (3, 1, 2), (1, 2, 3))
((2, 3, 1), (3, 1, 2), (1, 3, 2))
((2, 3, 1), (3, 1, 2), (2, 1, 3))
((2, 3, 1), (3, 1, 2), (2, 3, 1))
((2, 3, 1), (3, 1, 2), (3, 1, 2))
((2, 3, 1), (3, 1, 2), (3, 2, 1))
((2, 3, 1), (3, 2, 1), (1, 2, 3))
((2, 3, 1), (3, 2, 1), (1, 3, 2))
((2, 3, 1), (3, 2, 1), (2, 1, 3))
((2, 3, 1), (3, 2, 1), (2, 3, 1))
((2, 3, 1), (3, 2, 1), (3, 1, 2))
((2, 3, 1), (3, 2, 1), (3, 2, 1))
((3, 1, 2), (1, 2, 3), (1, 2, 3))
((3, 1, 2), (1, 2, 3), (1, 3, 2))
((3, 1, 2), (1, 2, 3), (2, 1, 3))
((3, 1, 2), (1, 2, 3), (2, 3, 1))
((3, 1, 2), (1, 2, 3), (3, 1, 2))
((3, 1, 2), (1, 2, 3), (3, 2, 1))
((3, 1, 2), (1, 3, 2), (1, 2, 3))
((3, 1, 2), (1, 3, 2), (1, 3, 2))
((3, 1, 2), (1, 3, 2), (2, 1, 3))
((3, 1, 2), (1, 3, 2), (2, 3, 1))
((3, 1, 2), (1, 3, 2), (3, 1, 2))
((3, 1, 2), (1, 3, 2), (3, 2, 1))
((3, 1, 2), (2, 1, 3), (1, 2, 3))
((3, 1, 2), (2, 1, 3), (1, 3, 2))
((3, 1, 2), (2, 1, 3), (2, 1, 3))
((3, 1, 2), (2, 1, 3), (2, 3, 1))
((3, 1, 2), (2, 1, 3), (3, 1, 2))
((3, 1, 2), (2, 1, 3), (3, 2, 1))
((3, 1, 2), (2, 3, 1), (1, 2, 3))
((3, 1, 2), (2, 3, 1), (1, 3, 2))
((3, 1, 2), (2, 3, 1), (2, 1, 3))
((3, 1, 2), (2, 3, 1), (2, 3, 1))
((3, 1, 2), (2, 3, 1), (3, 1, 2))
((3, 1, 2), (2, 3, 1), (3, 2, 1))
((3, 1, 2), (3, 1, 2), (1, 2, 3))
((3, 1, 2), (3, 1, 2), (1, 3, 2))
((3, 1, 2), (3, 1, 2), (2, 1, 3))
((3, 1, 2), (3, 1, 2), (2, 3, 1))
((3, 1, 2), (3, 1, 2), (3, 1, 2))
((3, 1, 2), (3, 1, 2), (3, 2, 1))
((3, 1, 2), (3, 2, 1), (1, 2, 3))
((3, 1, 2), (3, 2, 1), (1, 3, 2))
((3, 1, 2), (3, 2, 1), (2, 1, 3))
((3, 1, 2), (3, 2, 1), (2, 3, 1))
((3, 1, 2), (3, 2, 1), (3, 1, 2))
((3, 1, 2), (3, 2, 1), (3, 2, 1))
((3, 2, 1), (1, 2, 3), (1, 2, 3))
((3, 2, 1), (1, 2, 3), (1, 3, 2))
((3, 2, 1), (1, 2, 3), (2, 1, 3))
((3, 2, 1), (1, 2, 3), (2, 3, 1))
((3, 2, 1), (1, 2, 3), (3, 1, 2))
((3, 2, 1), (1, 2, 3), (3, 2, 1))
((3, 2, 1), (1, 3, 2), (1, 2, 3))
((3, 2, 1), (1, 3, 2), (1, 3, 2))
((3, 2, 1), (1, 3, 2), (2, 1, 3))
((3, 2, 1), (1, 3, 2), (2, 3, 1))
((3, 2, 1), (1, 3, 2), (3, 1, 2))
((3, 2, 1), (1, 3, 2), (3, 2, 1))
((3, 2, 1), (2, 1, 3), (1, 2, 3))
((3, 2, 1), (2, 1, 3), (1, 3, 2))
((3, 2, 1), (2, 1, 3), (2, 1, 3))
((3, 2, 1), (2, 1, 3), (2, 3, 1))
((3, 2, 1), (2, 1, 3), (3, 1, 2))
((3, 2, 1), (2, 1, 3), (3, 2, 1))
((3, 2, 1), (2, 3, 1), (1, 2, 3))
((3, 2, 1), (2, 3, 1), (1, 3, 2))
((3, 2, 1), (2, 3, 1), (2, 1, 3))
((3, 2, 1), (2, 3, 1), (2, 3, 1))
((3, 2, 1), (2, 3, 1), (3, 1, 2))
((3, 2, 1), (2, 3, 1), (3, 2, 1))
((3, 2, 1), (3, 1, 2), (1, 2, 3))
((3, 2, 1), (3, 1, 2), (1, 3, 2))
((3, 2, 1), (3, 1, 2), (2, 1, 3))
((3, 2, 1), (3, 1, 2), (2, 3, 1))
((3, 2, 1), (3, 1, 2), (3, 1, 2))
((3, 2, 1), (3, 1, 2), (3, 2, 1))
((3, 2, 1), (3, 2, 1), (1, 2, 3))
((3, 2, 1), (3, 2, 1), (1, 3, 2))
((3, 2, 1), (3, 2, 1), (2, 1, 3))
((3, 2, 1), (3, 2, 1), (2, 3, 1))
((3, 2, 1), (3, 2, 1), (3, 1, 2))
((3, 2, 1), (3, 2, 1), (3, 2, 1))
于 2013-10-02T16:04:44.617 回答