Difference between consecutive elements in list [duplicate]
You could utilize enumerate, zip and list comprehensions: >>> a = [0, 4, 10, 100] # basic enumerate without condition: >>> [x – a[i – 1] for i, x in enumerate(a)][1:] [4, 6, 90] # enumerate with conditional inside the list comprehension: >>> [x – a[i – 1] for i, x in enumerate(a) if i … Read more