Given lists in a list, find the maximum sum of elements of list in a list of lists.
Input : [[1, 2, 3], [4, 5, 6], [10, 11, 12], [7, 8, 9]] Output : 33 Explanation: sum of all lists in the given list of lists are: list1 = 6, list2 = 15, list3 = 33, list4 = 24 so the maximum among these is of Input : [[3, 4, 5], [1, 2, 3], [0, 9, 0]] Output : 12
Method 1 : Traversal of list in lists
We can traverse in the lists inside the list and sum up all the elements in a given list and by max function get the maximum of sum of all elements in lists of list.
Method 2 : Traversal of list
Traverse in the outer list only, and sum all elements in the inner lists by using sum() function, find the sum of all the lists and get the maximum of all the sum calculated.
Method 3 : Sum and Max function
The above syntax of max() function allows us to find the sum of list in list using the key=sum. max(list1, key=sum), this finds the list with maximum sum of elements and then sum(max(list1, key=sum)) returns us the sum of that list.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Program to count number of lists in a list of lists
- Python | Ways to sum list of lists and return sum list
- Python | Zipping two lists of lists
- Python - Convert Lists into Similar key value lists
- Python | Sorting list of lists with similar list elements
- Python | Merge List with common elements in a List of Lists
- Python | Get positive elements from given list of lists
- Python | Find common elements in list of lists
- Python | Convert column to separate elements in list of lists
- Python | Uncommon elements in Lists of List
- Python program to apply itertools.product to elements of a list of lists
- Python - Sum of different length Lists of list
- Python | Check if a list exists in given list of lists
- Python | Convert list into list of lists
- Python | Convert List of lists to list of Strings
- Python - Convert Key-Value list Dictionary to List of Lists
- Python - Convert List of Dictionaries to List of Lists
- Python | Maximum and Minimum value from two lists
- Python | Print all the common elements of two lists
- Python | Split the Even and Odd elements into two different lists
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.