Example:
tuple = ("python", "includehelp", 43, 54.23)
Finding the maximum difference between tuple pairs
We are given a list of tuples with integer values. We need to create a Python program to find the maximum difference between tuple pairs.
Input:
tupList = [(5, 7), (2, 6), (1, 9), (1, 3)]
Output:
8
Explanation:
Absolute difference of all tuples :
(5, 7) = 2
(2, 6) = 4
(1, 9) = 8
(1, 3) = 2
Method 1:
One method to solve the problem is by creating a list with the absolute difference of all tuples of the list. And find the maximum value out of all these values.
Output:
Method 2:
Another approach is by using a lambda function to find the absolute difference of tuples of the list. The resultant is then passed to the max() function. And calculate the absolute difference.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer