python max return index code example

Example 1: index to min python

import numpy as np
index_min = np.argmin(values)

Example 2: python return list max inde

a.index(max(a))

Example 3: max value in python

# find largest item in the string
print(max("abcDEF")) 

# find largest item in the list
print(max([2, 1, 4, 3])) 

# find largest item in the tuple
print(max(("one", "two", "three"))) 
'two'

# find largest item in the dict
print(max({1: "one", 2: "two", 3: "three"})) 
3

# empty iterable causes ValueError
# print(max([])) 

# supressing the error with default value
print(max([], default=0))

Example 4: find location of max value in python list

>>> m = max(a)
>>> [i for i, j in enumerate(a) if j == m]
[9, 12]