If I have a Python dictionary, how do I get the key to the entry which contains the minimum value?
I was thinking about something to do with the min() function...
min()
Given the input:
{320:1, 321:0, 322:3}
It would return 321.
321
Best: min(d, key=d.get) -- no reason to interpose a useless lambda indirection layer or extract items or keys!
min(d, key=d.get)
lambda
>>> d = {320: 1, 321: 0, 322: 3} >>> min(d, key=d.get) 321
1.4m articles
1.4m replys
5 comments
57.0k users