How to loop through all but the last item of a list?

for x in y[:-1]

If y is a generator, then the above will not work.


the easiest way to compare the sequence item with the following:

for i, j in zip(a, a[1:]):
     # compare i (the current) to j (the following)