When it is required to find the maximum difference between tuple pairs, the 'max' method and the list comprehension can be used.
A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on). A list of tuple basically contains tuples enclosed in a list.
The list comprehension is a shorthand to iterate through the list and perform operations on it.
The 'max' method returns the maximum of values by taking an iterable as argument.
Below is a demonstration of the same −
my_list_1 = [(11, 14), (0, 78), (33, 67), (89, 0)] print("The list of tuple is : ") print(my_list_1) temp_val = [abs(b - a) for a, b in my_list_1] my_result = max(temp_val) print("The maximum difference among tuple pairs is : ") print(my_result)
The list of tuple is : [(11, 14), (0, 78), (33, 67), (89, 0)] The maximum difference among tuple pairs is : 89