我有两个清单:
frame = ["mercury", "noir", "silver", "white" ]
seat_colors = [
"coconut white", "yello", "black", "green", "cappuccino",
"orange", "chrome", "noir", "purple", "pink", "red",
"matte", "gray", "bermuda blue"
]
Run Code Online (Sandbox Code Playgroud)
我正在尝试将它们组合到一个列表中,其中每个帧都与每个座位颜色唯一匹配.
我想这样使用zip():
In [3]: zip(frame, colors)
Out[3]:
[('mercury', 'coconut white'),
('noir', 'yello'),
('silver', 'black'),
('white', 'green')]
Run Code Online (Sandbox Code Playgroud)
但它会截断到最小列表的长度.
我知道我可以通过以下方式遍历列表:
In [5]:
for f in frame:
for c in colors:
print "%s, %s" %(f, c)
Out [5]:
mercury, coconut white
mercury, yello
mercury, black
mercury, green
mercury, cappuccino
mercury, orange
mercury, chrome …Run Code Online (Sandbox Code Playgroud) python ×1