List comprehension for series of deltas

Posted by Yuval A on Stack Overflow See other posts from Stack Overflow or by Yuval A
Published on 2010-05-08T10:48:52Z Indexed on 2010/05/08 10:58 UTC
Read the original article Hit count: 236

Filed under:
|

How would you write a list comprehension in python to generate a series of n-1 deltas between n items in an ordered list?

Example:

L = [5,9,2,1,7]
RES = [5-9,9-2,2-1,1-7] = [4,7,1,6] # absolute values

© Stack Overflow or respective owner

Related posts about python

Related posts about list-comprehension