在嵌套字典中查找最大值 [英] Find Max in Nested Dictionary
本文介绍了在嵌套字典中查找最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
d = {
"local": {
"count": 1,
"health-beauty": {
"count": 1,
"tanning": {"count": 1}
}
},
"nationwide": {"count": 9.0},
"travel": {"count": 0}
}
code>全国是最大的。
In this instance "nationwide"
is the largest.
下面的代码可以更容易地附加到脚本中:
Code is below to make it easier to attach to scripts:
d = {'travel': {'count': 0}, 'local': {'count': 1, 'health-beauty': {'count': 1, 'tanning': {'count': 1}}}, 'nationwide': {'count': 9.0}}
推荐答案
>>> max(d, key=lambda x: d[x]['count'])
'nationwide'
这篇关于在嵌套字典中查找最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文