0

I know that this question looks like its been asked but this variation has not. I have a dictionary with the values {'John': 10, 'Chase': 11, 'Cole': '11'}. If i use the max function, I'll only get the first value with the max (Chase). However in my program, I need to get all of the values (Chase and Cole). Any help? I have 2 separate lists that are also combined into a dictionary. I have done:

for value in array1dictionary:
    if value == max(array1list):
        maxkeyarray.append(key)

but that does not work. Any advice?

1 Answers1

0

You can try this:

dictt = {'John': 10, 'Chase': 11, 'Cole': '11'}

max_val = max(dictt.values(), key = lambda x: int(x))

maxkeyarray = [key for key in dictt if int(dictt[key]) == max_val]

print(maxkeyarray)

Output:

['Chase', 'Cole']
Sushil
  • 5,440
  • 1
  • 8
  • 26