字典和集合
1.字典推导:
ll = [('Zhangsan',180),('Lisi',175),('xz',160)]
dd = {name:height for name,height in ll}
print(dd)
>>{'Zhangsan': 180, 'Lisi': 175, 'xz': 160}
2.如何处理查找不到的键
1).setdefault
例1:
ll = [('Zhangsan',180),('Lisi',175),('xz',160)]
dl = {}
for k
原创
2021-02-05 13:59:51 ·
78 阅读 ·
0 评论