I am having some trouble with halting my iteration up until I reach a certain point in my list using Python. I have a list that looks like:
lst = [-0.5, 44, 90, 132.22, 129.6, 89, 67.91, 12.5, 11, 0.0006, 10.2, 67, 89.07, 100, 132.224, 129.88, 120.1, 100, 89.5, 75, 40, 9.8, -0.4, 0.1, 90, 99, 112, 132.22]
I've asked a question similar to this before, in which the list was in a somewhat different pattern. This time, in each experiment series, the pressure starts of low, then rises to a maximum value, and lowers again.
I would like to obtain the index and value of each start and end point for each experiment.
For instance, there are three experiments in this list. The outputs would be:
E 1:
Start: (0, -0.5) # starts at index 0, value -0.5
End: (3, 132.22)
E 2:
Start: (9, 0.0006)
End: (14, 132.224)
E 3:
Start: (22, -0.4)
End: (27, 132.22)
I am currently trying to iterate over every value; however, comparing each value against another isn't exactly helpful. For instance, I'd like to break out of the loop if a Start
is found and then move forward to find the End.
. Based on what I've learned so far, I am trying to do something like this:
for idx, item in enumerate(lst):
current = item
next = lst[(idx + 1) % len(lst)]
if current < next:
print(current)
continue
if next < current:
print(next)
continue
If anyone can help me modify my code or help me think about another strategy, it would help me a lot.