赞
踩
要求:
dictScore = {"101":[67,88,45],"102":[97,68,85],"103":[98,97,95],"104":[67,48,45],"105":[82,58,75],"106":[96,49,65]}
返回每一个学生学号和自己最高分
分析:
(1)首先声明一个字典再去获取字典里的键对
- # 声明字典
- dict = {’a’:’shuilt’,’b’:’makedir’,’c’:’transofm’}
- # 获取键值对
- list1 = dict.items()
- print(list1)
(2)获取后直接用max()得出最高分
注意:
items() 主要用于提取词典中的key: value对
例如
- scores = {
- "Rick Sanchez": 70,
- "Morty Smith": 35,
- "Summer Smith": 82,
- "Jerry Smith": 23,
- "Beth Smith": 98
- }
-
- passed = [n for n,s in scores.items() if s>=65]
- print(passed)
得出代码:
- dictScore = {"101": [67, 88, 45], "102": [97, 68, 85], "103": [98, 97, 95], "104": [67, 48, 45], "105": [82, 58, 75], "106": [96, 49, 65] }
- for k, v in dictScore.items():
- print(k, max(v))
结果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。