Exercise 77
Repeat the previous exercise (Exercise 76) without using the max() method.
Solution
def maxList (L):
# initialization of the index of the maximum of the list
i = 0
for j in range (0, len (L)):
if L[i] < L[j]:
# we replace i by j
i = j
return i
# Example
L = [22, 7, 88, 41, 14, 88, 9]
print ("the first index of the maximum is:", maxList (L))
# the program output is: the first index of the maximum is: 2
Younes Derfoufi
my-courses.net
my-courses.net