Sometimes, while working with data, we might have a problem in which we need to find maximum differene between available pairs in list. This can be application to many problems in mathematics domain. Let’s discuss certain ways in which this task can be performed.
Method #1 : Using
max() + list comprehension
The combination of this functions can be used to perform this task. In this, we compute the absolute difference of all pairs and then return the max of it using
The original list : [(3, 5), (1, 7), (10, 3), (1, 2)] Maximum difference among pairs : 7
Method #2 : Using
max() + lambda
This is similar to above method. In this the task performed by list comprehension is solved using lambda function, providing the difference computation logic. Returns the max. difference pair.
The original list : [(3, 5), (1, 7), (10, 3), (1, 2)] Maximum difference among pairs : (10, 3)
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Sort tuple list by Nth element of tuple
- Python | Replace tuple according to Nth tuple element
- Python - Raise elements of tuple as power to another tuple
- Python - Convert Tuple String to Integer Tuple
- Python - Convert Tuple to Tuple Pair
- Python - Flatten tuple of List to tuple
- Python - Convert Tuple Matrix to Tuple List
- Python program to convert Set into Tuple and Tuple into Set
- Python | Maximum of Product Pairs in Tuple List
- Python - Pairs with Sum equal to K in tuple list
- Python - Similar index pairs in Tuple lists
- Python - Convert Matrix to overlapping Tuple Pairs
- Python program to count Bidirectional Tuple Pairs
- Python | Difference Between List and Tuple
- Difference between List VS Set VS Tuple in Python
- Python | Maximum element in tuple list
- Python - Get maximum of Nth column from tuple list
- Python - Maximum value in record list as tuple attribute
- Python - Maximum and Minimum K elements in Tuple
- Python - Maximum frequency in Tuple
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.