lst1 = ['a','b','c'] lst2 = [1,2,3] dic = {} for i in range(len(lst1)): #第一种方法 dic[lst1[i]] = lst2[i] print(dic) for i,j in zip(lst1,lst2): #第二种方法 print(i,j) dic[i] = j print(dic)
运行结果:
{'a': 1, 'c': 3, 'b': 2}
a 1
b 2
c 3
{'a': 1, 'c': 3, 'b': 2}
lst1 = ['a','b','c'] lst2 = [1,2,3] dic = {} for i in range(len(lst1)): #第一种方法 dic[lst1[i]] = lst2[i] print(dic) for i,j in zip(lst1,lst2): #第二种方法 print(i,j) dic[i] = j print(dic)
运行结果:
{'a': 1, 'c': 3, 'b': 2}
a 1
b 2
c 3
{'a': 1, 'c': 3, 'b': 2}