【发布时间】:2015-06-30 17:44:33
【问题描述】:
我有两个要压缩的列表
列表 A:
["hello ", "world "]
列表 B:
["one", "two", "three"]
我想像这样压缩列表中的元素:
[("hello","one")
("hello","two")
("hello","three")
("world","one")
("world","two")
("world","three")]
显然,我可以使用双 for 循环并附加元素,但我想知道这样做的好 pythonie 方式是什么?
【问题讨论】:
-
您所描述的概念是“Cartesian product”,可以使用
itertools.product来实现,如上面的链接所示。 -
这就是我要找的词...谢谢!
标签: python python-2.7