我有这样的列表:
[['I'],['want','love','like'],['cat',dog]]
我想创建一个函数,可以返回列表中所有单词的组合,如下所示:
[['I'],['want'],['cat']]
[['I'],['love'],['cat']]
[['I'],['like'],['cat']]
[['I'],['want'],['dog']]
[['I'],['love'],['dog']]
[['I'],['like'],['dog']]
PS:该功能必须可以使用任何n
个单词
答案 0 :(得分:5)
import itertools
for k in itertools.product(*lst):
print(k)