import operator
# 先通过sorted 和operator 函数对字典进行排序,然后输出最大value的键
classCount={"c":1,"b":4,"d":2,"e":6}
print(classCount.items())
SortedclassCount1= sorted(classCount.items(), key=operator.itemgetter(1), reverse=True)
print(SortedclassCount1[0][0])
# 通过max求字典最大value对应的key
print(max(classCount,key=classCount.get))

operator.itemgetter的用法参考博客https://blog.csdn.net/Big_Pai/article/details/88567626
本文介绍如何使用Python的sorted函数和operator模块对字典进行排序,以及如何利用max函数快速找到字典中最大值对应的键。通过具体示例展示了itemgetter的使用方法。
3625

被折叠的 条评论
为什么被折叠?



