Python | Min and Max value in list of tuples
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]