I have a list of arrays as follows: Array =[3, 6, 5, 7, 2, 4, 3, 5, 4, 5, 4, 7, 6, 7, 1, 7, 4, 6, 3]
example: Value = 3, 6, 5, 7, 2, 4, 3, 5, 4, 5, 4, 7, 6, 7, 1, 7, 4, 6, 3
valley/Peak = v, p, v, p, v, p, v, p, v, p, v, p, v, p, v, p, v, p,v
On
As Mark Ransom & SA.93 suggested, indexing in python starts from 0. Maybe you are more familiar with R... :) For your solution, try this;
def next_lowest_num(Array,num):
lst = []
for i in Array[Array.index(num):]:
if i >= num:
lst.append(i)
else:
lst.append(i)
break
return lst
print(next_lowest_num(Array=[3, 6, 5, 7, 2, 4, 3, 5, 4, 5, 4, 7, 6, 7, 1, 7, 4, 6, 3],num=3))
print(next_lowest_num(Array=[3, 6, 5, 7, 2, 4, 3, 5, 4, 5, 4, 7, 6, 7, 1, 7, 4, 6, 3],num=5))
# Output
[3, 6, 5, 7, 2]
[5, 7, 2]
Hope this Helps...
logic
assign the index to start from
assign the value of the starting index
make a loop starting from the starting index to the end of the loop
in the loop check if current number is smaller than the starting target
slice the list to create the result sublist
code
input
start_index = 0array = [3, 6, 5, 7, 2, 4, 3, 5, 4, 5, 4, 7, 6, 7, 1, 7, 4, 6, 3]output
[3, 6, 5, 7, 2]