Sort by each tuple's maximum
Write a Python program to sort tuples by their maximum value, largest first.
[(1, 5, 7), (3, 4, 2), (4, 9, 0)]
[(4, 9, 0), (1, 5, 7), (3, 4, 2)]
Approach
key=maxwithreverse=True.
Solution
print(sorted([(1, 5, 7), (3, 4, 2), (4, 9, 0)], key=max, reverse=True))[(4, 9, 0), (1, 5, 7), (3, 4, 2)]
Learn the concept
New to this topic? Read the lesson, then come back.