I'm having some trouble with iteration and keeping track of various indices and values at different points in my list (I'm new to Python).
I am running a series of cycles, but want to determine their starts and end times. Experiments starts at around 0 and end at around 50.
Here is what a list of cycles look like:
c = [0, 10, 11, 48, 50.5, 0.48, 17, 18, 23, 29, 33, 34.67, 50.1, 0.09, 7, 41, 45, 50]
Here is an example of what the output should look like:
C 1:
Start: (0, 0) # starts at index 0, value 0
End: (4, 50.5) #ends at index 4, value 50.5
C 2:
Start: (5, 0.48)
End: (12, 50.1)
C 3:
Start: (13, 0.09)
End: (17, 50)
One approach I can think of is to sort the c.
c.sort()
This will at least put all the start values at the beginning of the list and the end values at the end of the list. However, then I would lose track of their original indices. Anyone know of another approach?
EDIT:
This is what I have so far, if anyone can help modify, it would be great:
min = []
max = []
for i, (first,second) in enumerate(zip(c, c[1:])):
print(i, first, second)
if first < second:
min.append(first)
continue
if first > second:
max.append(first)
continue