Python Practice › List Programs › Program 51

Sublist with the highest sum

EasyList Programs · 51 of 100

Write a Python program to find the sublist whose elements add up to the highest total.

Advertisement
Input
[[11, 2, 3], [4, 15, 6], [10, 11, 12], [7, 8, 19]]
Output
[7, 8, 19]

Approach

  1. max with key=sum.

Solution

Python
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.

More list programs

← All 100 List Programs

Leave a Comment