python之找字典dict中的最大/小值
Posted sbj123456789
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python之找字典dict中的最大/小值相关的知识,希望对你有一定的参考价值。
dogdistance = {‘dog-dog‘: 33, ‘dog-cat‘: 36, ‘dog-car‘: 41, ‘dog-bird‘: 42}
min(dogdistance, key=dogdistance.get)
返回最小值的键值: ‘dog-dog‘
max(dogdistance, key=dogdistance.get)
返回最大值的键值: ‘dog-bird‘
这里key的用法为一个函数
参考:
https://docs.python.org/3/library/functions.html#max
https://blog.csdn.net/weixin_41770169/article/details/80816886
以上是关于python之找字典dict中的最大/小值的主要内容,如果未能解决你的问题,请参考以下文章