Given a list of numbers, I am trying to write a code that finds the difference between consecutive elements. For instance, A = [1, 10, 100, 50, 40] so the outp
A = [1, 10, 100, 50, 40]
You can do a list comprehension:
>>> A = [1, 10, 100, 50, 40] >>> l=[A[0]]+A >>> [abs(l[i-1]-l[i]) for i in range(1,len(l))] [0, 9, 90, 50, 10]