Get maximum number in each sublist using a map
Here we are using a map method to get the maximum element from each list using a Python map.
Python3
# Initialising List a = [[ 10 , 13 , 454 , 66 , 44 ], [ 10 , 8 , 7 , 23 ]] # find max in list ans = list ( map ( max , a)) # Printing max print (ans) |
Output:
[454, 23]
Time complexity: O(nm), where n is the number of sublists in the list a and m is the maximum length of any sublist.
Auxiliary space: O(n), where n is the number of sublists in the list a.
Python | Find maximum value in each sublist
Given a list of lists in Python, write a Python program to find the maximum value of the list for 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]