Python | Find the sublist with maximum value in given nested list
Given a list of list, the task is to find sublist with the maximum value in second column.
Examples:
Input : [['Paras', 90], ['Jain', 32], ['Geeks', 120],
['for', 338], ['Labs', 532]]
Output :['Labs', 532]
Input: [['Geek', 90], ['For', 32], ['Geeks', 120]]
Output: ['Geeks', 120]
Below are some tasks to achieve the above task.
Method #1: Using lambda
# Python code to find maximum value # in second column of list of list # Input list initialization Input = [['Paras', 90], ['Jain', 32], ['Geeks', 120], ['for', 338], ['Labs', 532]] # Using lambda Output = max(Input, key = lambda x: x[1]) # printing output print("Input List is :", Input) print("Output list is : ", Output) |
Input List is : [[‘Paras’, 90], [‘Jain’, 32], [‘Geeks’, 120], [‘for’, 338], [‘Labs’, 532]]
Output list is : [‘Labs’, 532]
Method #2: Using itemgetter
# Python code to find maximum value # in second column of list of list # Importing import operator # Input list initialization Input = [['Paras', 90], ['Jain', 32], ['Geeks', 120], ['for', 338], ['Labs', 532]] # Using itemgetter Output = max(Input, key = operator.itemgetter(1)) # Printing output print("Input List is :", Input) print("Output list is : ", Output) |
Input List is : [[‘Paras’, 90], [‘Jain’, 32], [‘Geeks’, 120], [‘for’, 338], [‘Labs’, 532]]
Output list is : [‘Labs’, 532]
Recommended Posts:
- Python | Find maximum length sub-list in a nested list
- Python | Find maximum value in each sublist
- Python | Convert nested sublist into tuples
- Python | Check if a nested list is a subset of another nested list
- Python | Maximum Sum Sublist
- Python | Shift sublist in list
- Python | Replace sublist with other in list
- Python | Sort a list according to the second element in sublist
- Python | Convert string List to Nested Character List
- Python | Pair and combine nested list to tuple list
- Python | Convert a nested list into a flat list
- Python | Convert given list into nested list
- Python | Test for nested list
- Nested List Comprehensions in Python
- Python | Intersection of two nested list
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.


