How to subtract the value from the previous value in a list in python?
Question: I am trying to take values in a list, such as `[1,2,3]` and subtract them from
each other. So it would return `[-1,-1]` because the first value is `1-2` and
the second value is `2-3`. How would i achieve this in python? I have tried

    
    
    [x-y for (x,y) in list]
    

but this gives a 'need more than one value to unpack error.'


Answer: You can also use a generator created by izipping the list with itself, offset
by one index.

    
    
    from itertools import izip, islice
    [x - y for x,y in izip(lst, islice(lst, 1, None))]
    

This is handy if for some reason `lst` was itself a generator, or otherwise
was not easily examined for its length ahead of time, or you just didn't want
to consume it directly.

