Beginner programmer here with an easy question I hope. I want to be able to compare the value of the first item in a list to the second item in the list to see if they are sequential.
so in this list: numblist = [1 , 2 , 3, 5, 6, 7, 8, 9, 11]
i want to be able to report on the gaps between 3-5 and 9-11 in the most efficient way.
My first try was to take the list and run the following for loop:
for i in numblist: if numblist[i] == numblist[i + 1] - 1: print 'yay' else: print 'gap'
But this creates an error when it gets to the last item in the list: IndexError: list index out of range. So what methods are available for referencing the next, previous and last items in sequential data?