def pairwise(seq):
    a, b = tee(seq)
next(b)
return zip(a, b)
for current_item, next_item in pairwise(y):
    if compare(current_item, next_item):
        pass
Python: Looping through all but the last item of a list