2025-plovdiv-testing-debugging/hands_on/local_maxima_part2/local_maxima.py
2025-09-23 16:31:03 +03:00

18 lines
No EOL
462 B
Python

def find_maxima(x):
"""Find local maxima of x.
Input arguments:
x -- 1D list of real numbers
Output:
idx -- list of indices of the local maxima in x
"""
idx = []
for i in range(len(x)):
if i == 0 and x[i] > x[i+1]:
idx.append(i)
elif i != len(x)-1 and x[i] > x[i-1] and x[i] > x[i+1]:
idx.append(i)
elif i== len(x)-1 and x[i] > x[i-1]:
idx.append(i)
return idx