
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Find maximum value in each sublist in Python
We are given a list of lists. In the inner lists or sublists we are required to find the maximum value in each.
With max and in
We design a for loop with in condition and apply the max function to get the maximum value in each of the sublist.
Example
Alist = [[10, 13, 454, 66, 44], [10, 8, 7, 23]] # Given list print("The given list:\n ",Alist) # Use Max res = [max(elem) for elem in Alist] # Printing max print("Maximum values from each element in the list:\n ",res)
Output
Running the above code gives us the following result −
The given list: [[10, 13, 454, 66, 44], [10, 8, 7, 23]] Maximum values from each element in the list: [454, 23]
With map and max
We keep applying the max function using map while iterating through the sublists.
Example
Alist = [[10, 13, 454, 66, 44], [10, 8, 7, 23]] # Given list print("The given list:\n ",Alist) # Use Max res =list(map(max, Alist)) # Printing max print("Maximum values from each element in the list:\n ",res)
Output
Running the above code gives us the following result −
The given list: [[10, 13, 454, 66, 44], [10, 8, 7, 23]] Maximum values from each element in the list: [454, 23]
- Related Articles
- Find the sublist with maximum value in given nested list in Python
- Program to find the maximum sum of circular sublist in Python
- Program to find sum of contiguous sublist with maximum sum in Python
- Get first element of each sublist in Python
- Get last element of each sublist in Python
- Program to find length of longest sublist with value range condition in Python
- Program to find maximum erasure value in Python
- Program to find length of shortest sublist with maximum frequent element with same frequency in Python
- Program to find sum of the minimums of each sublist from a list in Python
- Program to find maximum XOR for each query in Python
- Python program to find the second maximum value in Dictionary
- How to find the maximum value in each matrix stored in an R list?
- Program to find length of longest distinct sublist in Python
- Program to find maximum possible value of smallest group in Python
- Program to find maximum sum by flipping each row elements in Python

Advertisements