adjacent differences with a list comprehension

Phil Schmidt pschmidt at omnimn.com
Mon Mar 24 16:31:16 EST 2003


Given a list of numbers, such as:

L = [2, 5, 8, 3, 9, 1]

I want to generate a list containing the differences between adjacent
elements, i.e.,

Ld = [3, 3, -5, 6, -8]

I don't see how I can do this (easily/elegantly) with list
comprehensions.

Any suggestions? Thanks!




More information about the Python-list mailing list