在嵌套字典中查找最大值

问题描述:

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'