0 votes
1 view
in Python by (47.8k points)

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

Given the input:

{320:1, 321:0, 322:3}

It would return 321.

1 Answer

0 votes
by (107k points)

The best way to get the key corresponding to the minimum value within a dictionary is to use the following way:-

d = {320:1, 321:0, 322:3}

min(d, key=d.get) 

image

There is no reason to interpose a useless lambda indirection layer or extract items or keys.

Related questions

0 votes
1 answer
asked Jul 3, 2019 in Python by Sammy (47.8k points)
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...