在python中映射3个列表的值

时间:2016-03-31 21:12:24

标签: python python-2.7

我有3个名单。

名单:brad, scott, bryan

他们的相应年龄:20, 25, 23

他们喜欢的颜色:red, orange, green

当我遍历名单时,我希望获得名称20的年龄red和颜色brad

2 个答案:

答案 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])