How to return the max value in list in a dictionary
Question:
I have a dictionary with values that are a list:
dict1 = {'d1': [1, 1, 2], 'd11': [1, 1, 4, 1], 'd16': [1, 1, 5]}
I’m trying to change the dictionary so that list return the max value as an integer.
This what I want:
dict1 = {'d1': 2, 'd11': 4, 'd16': 5}
I’ve tried using max() but it’s not really working for me.
Answers:
def max_in_dict(list_dictionary):
return {key: max(list_dictionary[key]) for key in list_dictionary.keys()}
This should do.
I have a dictionary with values that are a list:
dict1 = {'d1': [1, 1, 2], 'd11': [1, 1, 4, 1], 'd16': [1, 1, 5]}
I’m trying to change the dictionary so that list return the max value as an integer.
This what I want:
dict1 = {'d1': 2, 'd11': 4, 'd16': 5}
I’ve tried using max() but it’s not really working for me.
def max_in_dict(list_dictionary):
return {key: max(list_dictionary[key]) for key in list_dictionary.keys()}
This should do.