【python】将两个列表合并为字典,其中一个列表为Key,一个列表为Value

先说函数:dict(zip(列表1,列表2))

列表1作为key,列表2作为value

下面看一下代码:

#定义两个列表
list1 = range(0,10)
list2 = range(10,20)

#合并为字典,调用dict(zip())
dict_name = dict(zip(list1,list2))

print(dict_name)

运行结果: 

{0: 10, 1: 11, 2: 12, 3: 13, 4: 14, 5: 15, 6: 16, 7: 17, 8: 18, 9: 19}​​​​​​​

猜你喜欢

转载自blog.csdn.net/lm3758/article/details/82703992