传递长度可变的参数列表

2024-10-01 02:25:09 发布

您现在位置:Python中文网/ 问答频道 /正文

这可能是个愚蠢的问题,所以我会尽量简单

我有一个不同数量的列表(x)的列表,我试图将每个列表传递给函数itertools.product(),但我无法让它工作

x = [[a, b, c], [d, e, f], [g, h, i]]
itertools.product(x[0], x[1], x[2]...)

我试过:

itertools.product(x[n] for n in range(len(x)))
itertools.product(n for n in x)

我的职能部门很可能会:

output = []
for product in itertools.product(x[n] for n in range(len(x))):
    output.append(product)
output """--> [(a, d), (a, e)...]"""

非常感谢


Tags: 函数in列表foroutput数量lenrange