Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16595

Subtracting list values from previous list values

$
0
0

If I have a list of values like this:

a=[5,4,3,2,1]

How would I then go about subtracting a value from the one before it and storing it in a new list? In this example, the new list would look like:

b=[1,1,1,1]

I'm assuming this could be done with a for loop, but I'm not sure how to index the values. The data I will be working with has hundreds of entries, so is there a way to reference a previous entry in a list?


Viewing all articles
Browse latest Browse all 16595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>