Exercise 76

Write a Python algorithm that determines the first index of the maximum in a given list using the max () method. Example if

L = [22, 7, 88, 41, 14, 88, 9]

, the algorithm returns the first index of the maximum which is 2.

Solution

def indexMax (L):
m = max (L)
index_max = L.index (m)
return index_max

# Example
L = L = [22, 7, 88, 41, 14, 88, 9]
print ("The maximum index is:", indexMax (L))
# The output of the program is: The maximum index is: 2
Younes Derfoufi
my-courses.net

Leave a Reply