想象一下这个列表
[[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]]
答案 0 :(得分: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))