I use code like this to iterate through a list when I also need the next item in the list:
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
How can I simplify this?
gives:
[2, 3, 1, 2]