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.



filter_none

edit
close

play_arrow

link
brightness_4
code

# Python code to Find maximum of list in nested list
  
# Initialising List
a = [[10, 13, 454, 66, 44], [10, 8, 7, 23]]
  
# find max in list
b = [max(p) for p in a]
  
# Printing max
print(b)

chevron_right


Output:

[454, 23]

 
Method #2: Using map

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python code to Find maximum of list in nested list
  
# 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)

chevron_right


Output:

[454, 23]


My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.