字典的操作在编写程序时比较常见,下面的操作是字典快速赋值比较有用:快快学起来吧
1.字典赋值默认值
a = ["a","b","c","d","e"]d = dict.fromkeys(a, 0);print(d) #结果:{'a': 0, 'b': 0, 'c': 0, 'd': 0, 'e': 0}
2.字典解压赋值
l = [1,2,3,4,5]dz = dict(zip(a,l)) #使用zipprint(dz) #结果:{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}