Write a Python program to Sort Tuples by their Maximum element


This program sorts a list of tuples val in reverse order using the sorted function, which is a built-in Python function that returns a new sorted list from the elements of an iterable. The argument passed to the sorted function is the list of tuples val converted to a list using the list function. After sorting the list of tuples in reverse order, the resulting sorted list of tuples is printed with the statement print("Sorted Tuples : " , s).

Source Code

val = [(4, 5, 5, 7), (1, 3, 7, 4), (19, 4, 5, 3), (1, 2)]
print("The original list is : " + str(val))
s = sorted(list(val))
s.reverse()
print("Sorted Tuples : " , s)
 

Output

The original list is : [(4, 5, 5, 7), (1, 3, 7, 4), (19, 4, 5, 3), (1, 2)]
Sorted Tuples :  [(19, 4, 5, 3), (4, 5, 5, 7), (1, 3, 7, 4), (1, 2)]


Example Programs