Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting max min where the value of each key is a dictionary

I have the following, where the value for each key is a dictionary itself:

dict = { "key1": { "sal":24000, "xy":32, "age":54}
         "key2": { "sal":40000, "xy":22, "age":14}
         "key3": { "sal":50000, "xy":12, "age":64} }

I want to extract the maximum and minimum salary from here. i.e my output should be 24000 when I search for the minimum and 50000 when I search for the maximum.

How do I go about this? Thank you.

like image 999
Supriya Avatar asked Mar 13 '23 18:03

Supriya


1 Answers

max(dict.itervalues(), key=lambda x: x['sal'])

Just the same for minimum.

like image 83
Eugene Primako Avatar answered Mar 16 '23 07:03

Eugene Primako