python利用一对列表生成字典

方法一:

1
2
3
4
5
keys = ['a','b','c','d','e']       
values = [1,2,3,4,5]

d = dict(zip(keys, values))
print(d)

方法二:

1
2
3
4
5
keys = ['a','b','c','d','e']       
values = [1,2,3,4,5]

d = {k:v for k, v in zip(keys, values)}
print(d)