Here you go:
>>> [100.0 * a1 / a2 - 100 for a1, a2 in zip(a[1:], a)]
[5.0, -4.7619047619047592, -5.0, 5.2631578947368354]
Since you want to compare neighboring list items, it is better to create a list of pairs of interest to you, for example:
>>> a = range(5)
>>> a
[0, 1, 2, 3, 4]
>>> zip(a, a[1:])
[(0, 1), (1, 2), (2, 3), (3, 4)]
After that, it's just simple math to extract the percentage change from a pair of numbers.
source
share