I am working with Python3 and trying to create a oneliner that creates a generator that can return the cumulative sum of members of a list.
For example, given the list [1, 2, 3, 4]
, the generator expression should return 1, 3, 6, 10
in each call to next
.
I know how to do this with several lines of code. I would like to find a way to do it as a Python oneliner. The problem I find is how to access the previous values.
source https://stackoverflow.com/questions/73778080/python-generator-that-can-do-cumulative-sum-of-the-previous-elements
Comments
Post a Comment