What would be an elegant and pythonic way to implement cumsum?
Alternatively - if there\'a already a built-in way to do it, that would be even better of course...
Starting Python 3.8, and the introduction of assignment expressions (PEP 572) (:= operator), we can use and increment a variable within a list comprehension:
total = 0
[total := total + x for x in [1, 2, 3 ,4, 5]]
# [1, 3, 6, 10, 15]
This:
total to 0 which symbolizes the cumulative sumtotal with the current looped item (total := total + x) via an assignment expressionx to the new value of total