Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get all keys with the same value in a dictionary

I have a dictionary with all the letters and I want to get all the letters (so the keys) that occur the most.

letters = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'E': 1, 'F': 1, 'G': 1, 'H': 0, 'I': 0, 'J': 0, 'K': 0, 'L': 2, 'M': 4, 'N': 0, 'O': 1, 'P': 1, 'Q': 4, 'R': 0, 'S': 1, 'T': 2, 'U': 2, 'V': 0, 'W': 0, 'X': 1, 'Y': 0, 'Z': 0}

So M and Q are to be output

My Python version is 3.9.2

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

max_value = max(letters.values())
[key for key, val in letters.items() if val == max_value]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading