The problem statement asks to produce a new list whose element will be equal to the sum of the elements.
Input : list = [10, 20, 30, 40, 50] Output : [10, 30, 60, 100, 150] Input : list = [4, 10, 15, 18, 20] Output : [4, 14, 29, 47, 67]
We will use the concept of list comprehension and list slicing to get the cumulative sum of the list. The list comprehension has been used to access each element from the list and slicing has been done to access the elements from start to the i+1 element. We have used the sum() method to sum up the elements of the list from start to i+1.
Below is implementation of above approach :
[10, 30, 60, 100, 150]
- Python | Pandas Series.cummin() to find cumulative minimum of a series
- Python | Pandas series.cumprod() to find Cumulative product of a Series
- Python | Pandas series.cummax() to find Cumulative maximum of a series
- Python program to find sum of elements in list
- Python | Pandas Series.cumsum() to find cumulative sum of a Series
- Python program to find smallest number in a list
- Python program to find second largest number in a list
- Python program to find all Strong Numbers in given list
- Python program to find N largest elements from a list
- Python program to find largest number in a list
- Python program to find number of m contiguous elements of a List with a given sum
- Python program to find sum of absolute difference between all pairs in a list
- Python program to find middle of a linked list using one traversal
- Python - Cumulative Records Product
- Python | CAP - Cumulative Accuracy Profile analysis
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.