Index of min or max element
To find the index of the element with the minimum or maximum value in a list, you can use the min()
and max()
functions to get the minimum or maximum value in the list, and then use the list.index()
method to find the index of that value.
def min_element_index(arr): return arr.index(min(arr)) def max_element_index(arr): return arr.index(max(arr)) min_element_index([3, 5, 2, 6, 10, 7, 9]) # 2 max_element_index([3, 5, 2, 6, 10, 7, 9]) # 4