I came across this problem when in an interview. The requirement is to realize cumulative sum in one line of python. My answer is
def cum_sum(nums):
return [sum(nums[0:i+1]) for i in range(len(nums))]
This is very ugly, the previous result has not been used later which results in redundant calculations. I think there must have some high-level way to implement it.
Any help is welcomed. Thanks.