python index max list code example

Example 1: python index of max value in list

# any list
a = [1, 7, 3, 12, 5]

# index of minimum element
# if more than 1 minimum, 
# first index is returned
min_index = a.index(min(a))

# index of maximum element
max_index = a.index(max(a))

Example 2: python index max list

number_list = [1, 2, 3]
max_value = max(number_list)
# Return the max value of the list
max_index = number_list.index(max_value)
# Find the index of the max value
print(max_index)

Example 3: index of maximum value in list python

[i for i, x in enumerate(l) if x == max(l)]

Example 4: maximum and index of a list pythopn

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

Tags:

Java Example