The computation of min and max value is a quite common utility in any programming domain be it development or any other field that includes any programming constructs. Sometimes, data can come in the format of tuples and min and max operations have to be performed in them. Let’s discuss certain ways in which this is handled.
Method #1 : Using
In this method, we use the python inbuilt
max functions to perform the task of getting the minimum and maximum value of a particular element position.
The original list is : [(2, 3), (4, 7), (8, 11), (3, 6)] The min and max of index 1 : (2, 8) The min and max of index 2 : (3, 11)
Method #2 : Using
map() + zip()
This is the more elegant way to perform this particular task. In this task we use
map function to link the elements to the
zip functions that accumulates to perform the functionality of min function or max function.
The original list is : [(2, 3), (4, 7), (8, 11), (3, 6)] The indices wise maximum number : [8, 11] The indices wise minimum number : [2, 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 | Remove tuples having duplicate first value from given list of tuples
- Python | Remove duplicate tuples from list of tuples
- Python | Find the tuples containing the given element from a list of tuples
- Python | Remove tuples from list of tuples if greater than n
- Python | Count tuples occurrence in list of tuples
- Python | Combining tuples in list of tuples
- Python | Convert string tuples to list tuples
- Python - Filter all uppercase characters Tuples from given list of tuples
- Python program to find Tuples with positive elements in List of tuples
- Python program to find tuples which have all elements divisible by K from a list of tuples
- Python | Min/Max value in float string list
- Python - Sort dictionary by max/min element in value list
- Python | How to Concatenate tuples to nested tuples
- Python | Max/Min value in Nth Column in Matrix
- Python - Convert Tuple value list to List of tuples
- List Methods in Python | Set 1 (in, not in, len(), min(), max()...)
- Python | Find Min/Max in heterogeneous list
- Python | Convert list of tuples to list of list
- max() and min() in Python
- Use of min() and max() in Python
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.