AlexZ AlexZ - 2 months ago 28
Python Question

Find Max in Nested Dictionary

d = {
"local": {
"count": 1,
"health-beauty": {
"count": 1,
"tanning": {"count": 1}
}
},
"nationwide": {"count": 9.0},
"travel": {"count": 0}
}


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}}

Answer
>>> max(d, key=lambda x: d[x]['count'])
'nationwide'