【发布时间】:2019-06-09 17:42:11
【问题描述】:
我想知道您是否知道其他/更好的方法(没有 max 方法)来获取字典中得分最高的键? :
report_card = {'french' : 14,
'english' : 12,
'math' : 16,
'chemistry' : 19,
'sport' : 14}
max = 0
for subject, score in report_card.items():
if max < report_card[subject]:
max = report_card[subject]
for subject, score in report_card.items():
if max == report_card[subject]:
print(f"The subject with the highest score is {subject} with {score} points")
【问题讨论】:
-
为什么没有 max 函数?
-
保持你正在做的跑步最大值可能是最好的方法
-
Getting key with maximum value in dictionary? 的可能重复项。此线程上至少有 4 或 5 个答案不使用
max。 -
我不想使用“max”来训练我的逻辑和娱乐(我开始编程)
标签: python python-3.x dictionary key key-value