max dictionary value python code example
Example 1: python get the key with the max or min value in a dictionary
# Basic syntax:
key_with_max_value = max(dictionary, key=dictionary.get)
# Note, to get the max value itself, you can do either of the following:
max_value = dictionary[max(dictionary, key=dictionary.get)]
max_value = max(dictionary.values())
# Example usage:
dictionary = {"a": 1, "b": 2, "c": 3}
max(dictionary, key=dictionary.get)
--> 'c'
Example 2: js max value of array
let numbers = [4, 13, 27, 0, -5];
Math.max.apply(null, numbers);
Example 3: index of maximum value in list python
[i for i, x in enumerate(l) if x == max(l)]