Sublist with the highest sum
Write a Python program to find the sublist whose elements add up to the highest total.
[[11, 2, 3], [4, 15, 6], [10, 11, 12], [7, 8, 19]]
[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))[7, 8, 19]
Line by line
The sums are 16, 25, 33 and 34.
Learn the concept
New to this topic? Read the lesson, then come back.