获取与字典内最小值对应的键 [英] Get the key corresponding to the minimum value within a dictionary

查看:687
本文介绍了获取与字典内最小值对应的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个Python字典,如何获得包含最小值的条目的密钥?

If I have a Python dictionary, how do I get the key to the entry which contains the minimum value?

我正在考虑与 min() function ...

I was thinking about something to do with the min() function...

给定输入:

{320:1, 321:0, 322:3}

它将返回 321

推荐答案

最佳: code> min(d,key = d.get) - 没有理由插入一个无用的 lambda 间接层或提取项目或钥匙!

Best: min(d, key=d.get) -- no reason to interpose a useless lambda indirection layer or extract items or keys!

这篇关于获取与字典内最小值对应的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆