Python | Find maximum value in each sublist
Given list of lists in Python, write a Python program to find maximum value of list each sub-list.
Examples:
Input : [[10, 13, 454, 66, 44], [10, 8, 7, 23]] Output : [454, 23] Input : [[15, 12, 27, 1, 33], [101, 58, 77, 23]] Output : [33, 101]
Method #1: Using list comprehension.
# Python code to Find maximum of list in nested list # Initialising Lista = [[10, 13, 454, 66, 44], [10, 8, 7, 23]] # find max in listb = [max(p) for p in a] # Printing maxprint(b) |
Output:
[454, 23]
Method #2: Using map
# Python code to Find maximum of list in nested list # Initialising Lista = [[10, 13, 454, 66, 44], [10, 8, 7, 23]] # find max in listans = list(map(max, a)) # Printing maxprint(ans) |
Output:
[454, 23]



