Python Practice › List Programs › Program 51
Sublist with the highest sum
Write a Python program to find the sublist whose elements add up to the highest total.
Input
[[11, 2, 3], [4, 15, 6], [10, 11, 12], [7, 8, 19]]
Output
[7, 8, 19]
Approach
maxwithkey=sum.
Solution
data = [[11, 2, 3], [4, 15, 6], [10, 11, 12], [7, 8, 19]]print(max(data, key=sum))Output
[7, 8, 19]
Line by line
Line 2
The sums are 16, 25, 33 and 34.
Learn the concept
New to this topic? Read the lesson, then come back.