使用2个列表创建字典

时间:2018-03-23 15:16:55

标签: python python-3.x

我有2个名单:

name = ["Stirling","Lana","Cyril","Pam","Ray","Cheryl"]

alias =["Duchess","Truckasaurus","Chet","Cookie Monster","Gilles de Rais","Cherlene"]

我需要创建一个字典,使得名称是键,别名是值,以这种特殊方式:

Stirling : Duchess

此外,我必须使用for循环来执行此操作。

1 个答案:

答案 0 :(得分:1)

你可以简单地zip

name = ["Stirling","Lana","Cyril","Pam","Ray","Cheryl"]

alias =["Duchess","Truckasaurus","Chet","Cookie Monster","Gilles de Rais","Cherlene"]

my_dict = dict(zip(name, alias))