Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Compare current element in one list to next element in another list

I have two equally long lists representing the start and end frames of an event. They look something like this:

START     END
111        113
118        133
145        186

The next element of the START list is always going to be bigger than the previous element in the END lists a.k.a 118 is always going to be bigger than 113. I am trying to calculate the difference between the next element of the START list to the previous element in the END list a.k.a 118-113. I want to do this for every element, however I am having difficulties accessing the elements for the proper calculation. Here is what I have so far:

def estimateAverageBlinkInterval(blinkStartFrame, blinkStopFrame):
    
    estimateAverage = []
    
    for i in range(0, len(blinkStartFrame)):
        print(blinkStartFrame)
        for j in range(0, len(blinkStopFrame)):
            print(blinkStopFrame[j])
            estimateAverage.append(blinkStartFrame[i+1]-blinkStopFrame[j])
        
    return mean(estimateAverage) 

I am essentially iterating over both lists, I tried ‘blinkStartFrame[:-1]’ at the for loop but that doesn’t do anything and with the current [i+1] I am getting an ‘IndexError: list index out of range’ which makes sense as i am trying to access and element the loop hasn’t iterated over yet. Any suggestions are more than welcome, thank you!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Is this that you’re looking for ?
You can compare start[i] with end[i-1] ?

start = [111,118, 145]
end = [113, 133, 186]

for i in range(1, len(start)):
    print(start[i] - end[i-1])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading