# Aassas

Asasasa
user_2839494219
abc
2 years ago
1.4 kB
1
Indexable
Never
```def localMaxMin(list):
mx = []
mn = []
#if index of list is local min or max
if(list[0] > list[1]):
mx.append(0)
elif(list[0] < list[1]):
mn.append(0)

# Iterating over all points to check
# local maxima and local minima
for i in range(1, len(list)-1):

# Check whether point is local min
if(list[i-1] > list[i] < list[i + 1]):
mn.append(i)

# Check whether point is local max
elif(list[i-1] < list[i] > list[i + 1]):
mx.append(i)

#Checking last point in list
if(list[-1] > list[-2]):
mx.append(len(list)-1)
elif(list[-1] < list[-2]):
mn.append(len(list)-1)
return mx,mn

def outputer(mx,mn):
if(len(mx) > 0):
print("Points of Local maxima"\
" are : ", end ='')
print(*mx)
else:
print("There are no points of"\
" Local maxima.")

if(len(mn) > 0):
print("Points of Local minima"\
" are : ", end ='')
print(*mn)
else:
print("There are no points"\
" of Local minima.")
print("-"*10)

mx,mn = localMaxMin([10, 20, 15, 14, 13, 25, 5, 4, 3])
outputer(mx,mn)
mx,mn = localMaxMin([10, 20, 15, 10, 10, 25, 5, 4, 3])
outputer(mx,mn)
mx,mn = localMaxMin([4, 2, 3, 4])
outputer(mx,mn)
mx,mn = localMaxMin([5, 5, 5, 4])
outputer(mx,mn)```