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

21 lines
427 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
"""
maxima = []
for index in range(len(x)-2):
if x[index+1] > x[index] and x[index +1] > x[index+2]:
maxima.append(index+1)
return maxima
if __name__ == "__main__":
x = [1, 2, 2, 1]
print(find_maxima(x))