我有3个名单。
名单:brad, scott, bryan
他们的相应年龄:20, 25, 23
他们喜欢的颜色:red, orange, green
。
当我遍历名单时,我希望获得名称20
的年龄red
和颜色brad
。
答案 0 :(得分:1)
你匹配zip
任意数量的序列。
names = ['brad', 'scott', 'bryan']
colors = ['red', 'orange', 'green']
ages = [20, 25, 23]
for name, color, age in zip(names, colors, ages):
print name, color, age
答案 1 :(得分:0)
names = ['brad', 'scott', 'bryan']
colors = ['red', 'orange', 'green']
ages = [20, 25, 23]
for i, val in enumerate(names):
print "{} {} {}".format(val, colors[i], ages[i])