python 同时遍历两个列表并组成一个字典

dict1 = {
    
    }  # 创建空字典
list1 = ['a', 'b', 'c']  # 创建列表
list2 = ['1', '2', '3']  # 创建列表
for key, value in zip(list1, list2):
    print(key)
    print(value)
    dict1[key] = value  # 往字典中添加键值对

a
1
b
2
c
3

dict1

{‘a’: ‘1’, ‘b’: ‘2’, ‘c’: ‘3’}

猜你喜欢

转载自blog.csdn.net/weixin_44493841/article/details/121333167