Possible Duplicate:
Python: Looping through all but the last item of a list
Is there a better way of iterating through a list when you also need the next item (or any other arbitrary item) in the list? I use this, but maybe someone can do better...
values = [1, 3, 6, 7 ,9]
diffs = []
for i in range(len(values)):
try: diffs.append(values[i+1] - values[i])
except: pass
print diffs
gives:
[2, 3, 1, 2]