

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- Find maximum value in each sublist in Python
- Find maximum length sub-list in a nested list in Python
- Find a pair from the given array with maximum nCr value in Python
- Python - Convert given list into nested list
- Python – Count frequency of sublist in given list
- Program to find sum of contiguous sublist with maximum sum in Python
- Program to find the maximum sum of circular sublist in Python
- How to find the element from a Python list with a maximum value?
- Program to find length of longest sublist with given condition in Python
- Find a pair from the given array with maximum nCr value in C++
- Program to find length of longest sublist with value range condition in Python
- Program to find length of shortest sublist with maximum frequent element with same frequency in Python
- Python – Display the key of list value with maximum range
- Find a value whose XOR with given number is maximum in C++
- Find indices with None values in given list in Python
Advertisements