【发布时间】:2017-10-01 23:03:33
【问题描述】:
我有两个列表:
first = ["one", "two", "three"]
second = ["five", "six", "seven"]
我希望这两个列表的每一个组合,但第一个列表中的元素始终位于前面。我尝试过这样的事情:
for i in range(0, len(combined) + 1):
for subset in itertools.permutations(combined, i):
print('/'.join(subset))
“组合”是这两个列表的组合,但这给了我所有的可能性,我只想要第一个列表中的元素放在首位的那些。例如:
["onefive","twosix","twofive"]
等等。 有谁知道我该怎么做这个?
【问题讨论】:
-
在这个例子中,你想要所有 9 种组合吗?
-
是的,我确实想要所有 9 种组合。
标签: python python-2.7 python-3.x list