'How to find the key corresponding to the maximum value in a dictionary of dictionary using max() function?

I know how to find the key corresponding to the maximum value in a dictionary, thanks to the answers to the following quesyions on Stackoverflow -

Print the key of the max value in a dictionary the pythonic way,

key corresponding to maximum value in python dictionary,

Getting key with maximum value in dictionary?, etc.

But I am not being able to understand how these will work out for a dictionary of dictionary.

Example-
I have a dictionary of dictionary d[x][l]. Suppose, I need to find the following- For a particular l='green', I need to find the corresponding value of x for which d[x]['green'] is maximum.

How to use the max() function in this case? I want to avoid looping over. I was hoping to find something equivalent to the MATLAB way of doing it in a matrix- max(d(:,l)).

d[x][l] takes integer values, and so does x.



Solution 1:[1]

d = {10: 100, 81:500}
s=max(d,key=d.get)
print(s)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sahil Panhalkar