How to find the top 3 keys of a dictionary having largest values in Python

1 Answer

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

keys = sorted(dic, key=dic.get, reverse=True)[:3]

print(keys)




'''
run:

['b', 'e', 'd']

'''


 



answered Mar 15, 2023 by avibootz

Related questions

1 answer 180 views
2 answers 187 views
1 answer 171 views
1 answer 166 views
1 answer 189 views
...