Possible Duplicate:
Python – Differences between elements of a list
I have a list and I want to find difference between consecutive elements:
a = [0, 4, 10, 100]
find_diff(a)
>>> [4,6,90]
How would you code find_diff() function? I can code this with “for” iterator but I am sure there are very simple ways to do it with a simple one liner.
You could utilize
enumerate,zipand list comprehensions:Performance-wise, there seems to be not too much variance: