fixed find maxima function first 3 #7
2 changed files with 29 additions and 1 deletions
|
@ -1,6 +1,16 @@
|
||||||
|
from first import times_3
|
||||||
|
|
||||||
def test_times_3_integer():
|
def test_times_3_integer():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def test_times_3_string():
|
def test_times_3_string():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_times_3_list():
|
||||||
|
value = [1]
|
||||||
|
expected = [1, 1, 1]
|
||||||
|
|
||||||
|
result = times_3(value)
|
||||||
|
|
||||||
|
assert result == expected
|
|
@ -7,4 +7,22 @@ def find_maxima(x):
|
||||||
Output:
|
Output:
|
||||||
idx -- list of indices of the local maxima in x
|
idx -- list of indices of the local maxima in x
|
||||||
"""
|
"""
|
||||||
return []
|
localmax = []
|
||||||
|
|
||||||
|
for i, num in enumerate(x):
|
||||||
|
if i == 0:
|
||||||
|
if x[i+1] < x[i]:
|
||||||
|
localmax.append(i)
|
||||||
|
elif i == len(x)-1:
|
||||||
|
if x[i-1] < x[i]:
|
||||||
|
localmax.append(i)
|
||||||
|
else:
|
||||||
|
if x[i+1] < x[i] and x[i-1] < x[i]:
|
||||||
|
localmax.append(i)
|
||||||
|
|
||||||
|
return localmax
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
x = [1, 2, 3]
|
||||||
|
print(find_maxima(x))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue