← Back to challenges

Cumulative List Sum

PythonHardarraysmathnumbersloops

Instructions

Create a function that takes a list of numbers and returns a list where each number is the sum of itself + all previous numbers in the list.

Examples

cumulative_sum([1, 2, 3]) ➞ [1, 3, 6]

cumulative_sum([1, -2, 3]) ➞ [1, -1, 2]

cumulative_sum([3, 3, -2, 408, 3, 3]) ➞ [3, 6, 4, 412, 415, 418]

Notes

Return an empty list if the input is an empty list.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Return the Middle Character(s) of a String