Python - Find maximum value in each sublist Last Updated : 24 Dec, 2024 Comments Improve Suggest changes Like Article Like Report Finding the maximum value in each sublist involves iterating through a list of lists and identifying the largest element within each sublist. This operation is useful for analyzing data sets, and extracting the most significant values from grouped information. In this article, we will explore methods to find maximum value. Using map()map() function applies a specified function, max() to each sublist in the list of lists. It processes each sublist and returns the result in a new list.Example: Python a = [[10, 13, 454, 66, 44], [10, 8, 7, 23]] # Using map with max res = list(map(max,a)) print(res) Output[454, 23] Explanation:It applies max() to each sublist in a.It returns the maximum value from each sublist .Let's understand more methods to find maximum in each sublist.Table of ContentUsing list comprehension Using reduce()Using for loopUsing list comprehension list comprehension with max() is a simple way to get the highest value from each sublist. It works well for medium-sized datasets, balancing speed and ease of understanding.Example: Python a = [[10, 13, 454, 66, 44], [10, 8, 7, 23]] # Using list comprehension with max() res = [max(sublist) for sublist in a] print(res) Output[454, 23] Explanation:It applies max() to each sublist in a.It returns the maximum value from each sublist .Using reduce()reduce() function can be used to find the maximum value in each sublist by iterating through the elements. This approach maintains the order of the sublists while calculating the maximum.Example: Python from functools import reduce a = [[10, 13, 454, 66, 44], [10, 8, 7, 23]] # Using reduce to find the max value in each sublist res = [reduce(lambda x, y: x if x > y else y, sublist) for sublist in a] print(res) Output[454, 23] Explanation:This code finds the maximum value in each sublist.It returns the results .Using for loopfor loop find the highest value in each sublist. It processes each sublist one by one and adds the maximum value to the result.Example: Python a = [[10, 13, 454, 66, 44], [10, 8, 7, 23]] # Using for loop with max() res = [] for sublist in a: res.append(max(sublist)) print(res) Output[454, 23] Explanation:It finds the maximum value in each sublist.It adds the results to the res list. Comment More infoAdvertise with us Next Article Python - Find maximum value in each sublist everythingispossible Follow Improve Article Tags : Python python-list Python list-programs Practice Tags : pythonpython-list Similar Reads Use of min() and max() in Python Prerequisite: min() max() in Python Let's see some interesting facts about min() and max() function. These functions are used to compute the maximum and minimum of the values as passed in its argument. or it gives the lexicographically largest value and lexicographically smallest value respectively, 2 min read Find Maximum of two numbers in Python Finding the maximum of two numbers in Python helps determine the larger of the two values. For example, given two numbers a = 7 and b = 3, you may want to extract the larger number, which in this case is 7. Let's explore different ways to do this efficiently.Using max()max() function is the most opt 2 min read Python | Max/Min value in Nth Column in Matrix Sometimes, while working with Python Matrix, we may have a problem in which we require to find the minimum and maximum value of a particular column. This can have a possible application in day-day programming and competitive programming. Let's discuss certain ways in which this task can be performed 7 min read Maximum and Minimum element in a Set in Python We are given a set and our task is to find the maximum and minimum elements from the given set. For example, if we have a = {3, 1, 7, 5, 9}, the maximum element should be 9, and the minimum element should be 1.Letâs explore different methods to do it:1. Using min() & max() functionThe built-in m 3 min read Get the index of maximum value in DataFrame column Pandas DataFrame is two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Let's see how can we get the index of maximum value in DataFrame column.Observe this dataset first. We'll use 'Weight' and 'Salary' columns of this data in order t 2 min read How to Get the maximum value from the Pandas dataframe in Python? Python Pandas max() function returns the maximum of the values over the requested axis. Syntax: dataframe.max(axis) where, axis=0 specifies columnaxis=1 specifies rowExample 1: Get maximum value in dataframe row To get the maximum value in a dataframe row simply call the max() function with axis set 2 min read Python map function to find row with maximum number of 1's Given a boolean 2D array, where each row is sorted. Find the row with the maximum number of 1s. Examples: Input: matrix = [[0, 1, 1, 1], [0, 0, 1, 1], [1, 1, 1, 1], [0, 0, 0, 0]] Output: 2 We have existing solution for this problem please refer Find the row with maximum number of 1's. We can solve t 1 min read Find the sum and maximum value of the two column in excel file using Pandas In these articles, we will discuss how to read data from excel and perform some mathematical operation and store it into a new column in DataFrame. Suppose our excel file looks like this. sample_data.xlsx Then we have to compute the sum of two-column and find out the maximum value and store into a n 2 min read numpy.maximum() in Python numpy.maximum() function is used to find the element-wise maximum of array elements. It compares two arrays and returns a new array containing the element-wise maxima. If one of the elements being compared is a NaN, then that element is returned. If both elements are NaNs then the first is returned. 2 min read Python - max() function Python max() function returns the largest item in an iterable or the largest of two or more arguments. It has two forms. max() function with objectsmax() function with iterablePython max() function With ObjectsUnlike the max() function of C/C++, the max() function in Python can take any type of obje 4 min read Like