Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python | Find maximum value in each sublist

  • Last Updated : 14 Feb, 2019

Given list of lists in Python, write a Python program to find maximum value of list each sub-list.

Examples:

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

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 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)
Output:
[454, 23]

 
Method #2: Using map




# 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)
Output:
[454, 23]



My Personal Notes arrow_drop_up
Recommended Articles
Page :