-3

There exists a dictionary.

my_dict = {'alpha':{'a':1, 'b':2, 'c':3}}

How to return a single list with one key inside which refers to the greatest value. If there are multiple occurrences of the greatest value then return a list with keys of similar value.

taycants
  • 1
  • 2
  • 1
    Could you write the desired output please? – Fran Arenas Jan 30 '22 at 12:04
  • 2
    You haven't show any attempt here, so it's not clear what you're stuck on. You presumably know how to iterate a dictionary? – roganjosh Jan 30 '22 at 12:04
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Feb 08 '22 at 17:19
  • Does this answer your question? [Getting key with maximum value in dictionary?](https://stackoverflow.com/questions/268272/getting-key-with-maximum-value-in-dictionary) – Gino Mempin Aug 14 '22 at 06:36

1 Answers1

1

You can use max to get the maximum value, and extract the keys that has that value:

max_value = max(my_dict['alpha'].values())
print([key for key, value in my_dict['alpha'].items() if value == max_value])
Sash Sinha
  • 18,743
  • 3
  • 23
  • 40
sagi
  • 40,026
  • 6
  • 59
  • 84