我有两个清单:
SELECT g.*
FROM Galaxy g
WHERE NOT EXISTS (SELECT 1
FROM Planet p JOIN
Continent c
USING (PlanetID)
WHERE p.GalaxyID = g.GalaxyID
);
我的代码:
names = ['John', 'Mike']
years = ['1980','1975']
这会产生:
combination = []
for n, nvalue in enumerate(names):
for y, yvalue in enumerate(years):
combination.append([nvalue,yvalue])
print (combination)
我希望可能的组合,其中每一行在列表中都有一年的名称。因此,名字将首先出现在所有迭代中,然后是其他名称。同年可以出现多个名字。
必需的输出:
[['John', '1980'], ['John', '1975'], ['Mike', '1980'], ['Mike', '1975']]
答案 0 :(得分:4)
这个怎么样:
import itertools
names = ['John', 'Mike']
years = ['1980', '1975']
print [ zip(names, year_product)
for year_product in itertools.product(
years, repeat=len(names)) ]