用列表 B 的每个元素压缩列表 A 的每个元素 - 最好的“pythonie”方式

Geo*_*lov 1 python python-2.7

我有两个要压缩的列表

清单 A:

["hello ", "world "]
Run Code Online (Sandbox Code Playgroud)

名单乙:

["one", "two", "three"]
Run Code Online (Sandbox Code Playgroud)

我想像这样压缩列表中的元素:

[("hello","one")
("hello","two")
("hello","three")
("world","one")
("world","two")
("world","three")]
Run Code Online (Sandbox Code Playgroud)

显然,我可以使用 double for 循环并附加元素,但我想知道这样做的好的 pythonie 方法是什么?

mgi*_*son 5

这似乎是一个完美的用例 itertools.product

>>> import itertools
>>> list(itertools.product(['hello', 'world'], ['one', 'two', 'three']))
[('hello', 'one'), ('hello', 'two'), ('hello', 'three'), ('world', 'one'), ('world', 'two'), ('world', 'three')]
Run Code Online (Sandbox Code Playgroud)