How to find the key with minimum value in a dictionary with Python

4 Answers

0 votes
import operator

dic = {'a':13, 'b':96, 'c':8, 'd':24, 'e':36, 'f':17}

mn = min(dic.items(), key=operator.itemgetter(1))[0]

print(mn)




'''
run:

c

'''

 



answered Mar 23, 2023 by avibootz
0 votes
import operator

dic = {'a':13, 'b':96, 'c':8, 'd':24, 'e':36, 'f':17}

mn = min(dic.items(), key=operator.itemgetter(1))

print(mn)




'''
run:

('c', 8)

'''

 



answered Mar 23, 2023 by avibootz
0 votes
dic = {'a':13, 'b':96, 'c':8, 'd':24, 'e':36, 'f':17}

mn = min(dic, key = dic.get)

print(mn)




'''
run:

c

'''

 



answered Mar 23, 2023 by avibootz
0 votes
dic = {'a':13, 'b':96, 'c':8, 'd':24, 'e':36, 'f':17}

mn = min(dic, key=lambda key: dic[key])

print(mn)




'''
run:

c

'''

 



answered Mar 23, 2023 by avibootz
...