创建两个元素的3个列表根本不会使代码复杂化。
zip可以轻松地“翻转”多个列表的轴(将Y元素的X序列转换为X元素的Y序列),使其易于使用
itertools.product:
import itertoolsa = [1,2,3]b = [4,5,6]# Unpacking result of zip(a, b) means you automatically pass# (1, 4), (2, 5), (3, 6)# as the arguments to itertools.productoutput = list(itertools.product(*zip(a, b)))print(*output, sep="n")
哪个输出:
(1, 2, 3)(1, 2, 6)(1, 5, 3)(1, 5, 6)(4, 2, 3)(4, 2, 6)(4, 5, 3)(4, 5, 6)
与示例输出的排序不同,但是可能的替换集相同。



