When it is required to find the maximum element in a tuple list (i.e list of tuples), the 'max' method and the 'operator.itemgetter' method can be used.
The itemgetter fetches a specific item from its operand.
The 'max' method gives the maximum value present in an iterable that is passed as argument to it.
Below is a demonstration of the same −
from operator import itemgetter my_list = [('Will', 23), ('Jane', 21), ('El', 24), ('Min', 101)] print ("The list is : ") print(my_list) my_result = max(my_list, key = itemgetter(1)) print ("The name that has the maximum value is : ") print(my_result)
The list is : [('Will', 23), ('Jane', 21), ('El', 24), ('Min', 101)] The name that has the maximum value is : Min