Example:
tuple = ("python", "includehelp", 43, 54.23)
Finding the maximum element in tuple list
In this article, we are given a list of tuples. We need to create a Python program to find the maximum element in the tuple list.
Input:
[(4, 1, 6), (2, 3, 9), (12, 7, 5)]
Output:
12
We need to iterate through all the elements of the tuple list and find the maximum value from all of them which is our required value.
Method 1:
One method to find the maximum element of the tuple list is by iterating over the list of tuples using a generator expression and then finding the maximum value from the resultant collection/iterator using the max() method.
Output:
Method 2:
Another method to solve the problem is by flattening the list of tuples using the from_iterable() method from the chain library. Then, we will find the maximum value from the created the map() using the max() method.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer