Example:
tuple = ("python", "includehelp", 43, 54.23)
Maximum value in record list as tuple attribute
We are given a list of tuples with each tuple with values stored as records. We need to create a python program to extract the maximum value in the record list as a tuple attribute.
Input:
[('java', [4, 3, 8, 9]), ('python', [7, 1, 4, 2]), ('scala' , [4, 5, 6, 11])]
Output:
[('java', 9), ('python', 7), ('scala', 11)]
To extract the maximum value in the record, we will be traversing each tuple record and simply finding the largest value from the record.
Method 1:
One combination of methods in python that can perform the task is finding the maximum of each record using the max() method and extracting it using list comprehension by iterating the list of tuples.
Output:
Method 2:
One more combination that can be employed is mapping the list which uses a lambda function to extract tuple with value and maximum of record extracted using the the max() method.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer