Python Practice › Tuple Programs › Program 60

Sort by each tuple's maximum

EasyTuple Programs · 60 of 70

Write a Python program to sort tuples by their maximum value, largest first.

Advertisement
Input
[(1, 5, 7), (3, 4, 2), (4, 9, 0)]
Output
[(4, 9, 0), (1, 5, 7), (3, 4, 2)]

Approach

  1. key=max with reverse=True.

Solution

Python
print(sorted([(1, 5, 7), (3, 4, 2), (4, 9, 0)], key=max, reverse=True))
Output
[(4, 9, 0), (1, 5, 7), (3, 4, 2)]
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More tuple programs

← All 70 Tuple Programs