I have a list which stores scores of a game which is played in rounds. At each index, the score is stored such that it's equal to the total score scored up to and including that round.
- round 1 - 5 points are scored in this round
- round 2 - 3 points are scored in this round
- round 3 - 7 points are scored in this round
- round 4 - 4 points are scored in this round
This will result in
total_score = [5, 8, 15, 19]
How can I convert this neatly into a list which has the score of each round at each index, instead of the total score up to that round.
So I want to turn the above list into:
round_scores = [5, 3, 7, 4]
It's not particularly hard to do with just iterating over it and subtracting the score at the previous index from the score at the current index. But is there a neater way to do this? Maybe a one liner list comprehension? I'm fairly new to Python but I've seen some magic being done in a single line in other answers.