
- 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 the sublist with maximum value in given nested list in Python
A list can contain other list as its elements. In this article we are equal to find the sublist with maximum value which are present in a given list.
With max and lambda
The max and the Lambda function can together be used to give that sublist which has the maximum value.
Example
listA = [['Mon', 90], ['Tue', 32], ['Wed', 120]] # Using lambda res = max(listA, key=lambda x: x[1]) # printing output print("Given List:\n", listA) print("List with maximum value:\n ", res)
Output
Running the above code gives us the following result −
Given List: [['Mon', 90], ['Tue', 32], ['Wed', 120]] List with maximum value: ['Wed', 120]
With itergetter
We use itemgetter from index position 1 and apply a max function to get the sublist with maximum value.
Example
import operator listA = [['Mon', 90], ['Tue', 32], ['Wed', 120]] # Using itemgetter res = max(listA, key = operator.itemgetter(1)) # printing output print("Given List:\n", listA) print("List with maximum value:\n ", res)
Output
Running the above code gives us the following result −
Given List: [['Mon', 90], ['Tue', 32], ['Wed', 120]] List with maximum value: ['Wed', 120]
- Related Articles
- Find maximum value in each sublist in Python
- Find maximum length sub-list in a nested list in Python
- Python – Count frequency of sublist in given list
- Program to find sum of contiguous sublist with maximum sum in Python
- Find a pair from the given array with maximum nCr value in Python
- Python - Convert given list into nested list
- Program to find the maximum sum of circular sublist in Python
- Program to find length of longest sublist with given condition in Python
- Program to find length of shortest sublist with maximum frequent element with same frequency in Python
- How to find the element from a Python list with a maximum value?
- Program to find length of longest sublist with value range condition in Python
- Get first element with maximum value in list of tuples in Python
- Python – Display the key of list value with maximum range
- Nested list comprehension in python
- Find a pair from the given array with maximum nCr value in C++

Advertisements