Sometimes, while working with data, we might have a problem in which we need to find minimum 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
min() + 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 min of it using min().
The original list : [(3, 5), (1, 7), (10, 3), (1, 2)] Minimum difference among pairs : 1
Method #2 : Using
min() + 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 min. difference pair.
The original list : [(3, 5), (1, 7), (10, 3), (1, 2)] Minimum difference among pairs : (1, 2)
- Python - Minimum in each record value list
- Python | Index minimum value Record
- Python | Difference in Record Lists
- Python | True Record
- Python - Maximum Sum Record
- Python | Record Index Product
- Python - Remove Record if Nth Column is K
- Python | Exponentiate Kth Record Index
- Python - Value Dictionary from Record List
- Python - Maximum record value key in dictionary
- Python | Maximize Record list
- Python | Rear Addition of Record
- Python - Row with Maximum Record Element
- Python | Record elements Average in List
- Python - List lengths as record attribute
- Python - Nested record values summation
- Python - Test Record existence in Dictionary
- Python | Record Similar tuple occurrences
- Python | Column Average in Record List
- Python - Count elements in record 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 firstname.lastname@example.org. 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.