

- 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 minimum of each index in list of lists in Python
In some problems we need to identify the minimum of each element in a list. But in solving the matrix operations, we need to find the minimum of each column in the matrix. That needs us to find the minimum value from list of lists. Because each column of a matrix is a list of lists.
Using min() and zip()
In the below example we use the min() and zip(). Here the zip() function organizes the elements at the same index from multiple lists into a single list. Then we apply the min() function to the result of zip function using a for loop.
Example
List = [[90, 5, 46], [71, 33, 2], [9, 13, 70]] print("List : " + str(List)) # using min()+ zip() result = [min(index) for index in zip(*List)] print("minimum of each index in List : " + str(result))
Running the above code gives us the following result:
List : [[90, 5, 46], [71, 33, 2], [9, 13, 70]] minimum of each index in List : [9, 5, 2]
Using map() , min() and zip()
We can also use the map() and zip() together in a similar approach as above. Here we have the result of zip() applied to the min(). In place of for loop we use the map() for this purpose.
Example
List = [[0.5, 2.4, 7], [5.5, 1.9, 3.2], [8, 9.9, 10]] print("The list values are: " + str(List)) # using min() + map() + zip() result = list(map(min, zip(*List))) #result print("Minimum of each index in list of lists is : " + str(result))
Running the above code gives us the following result:
The list values are: [[0.5, 2.4, 7], [5.5, 1.9, 3.2], [8, 9.9, 10]] Minimum of each index in list of lists is : [0.5, 1.9, 3.2]
- Related Questions & Answers
- Minimum Index Sum of Two Lists in C++
- Python - Find starting index of all Nested Lists
- Find common elements in list of lists in Python
- Minimum Index Sum for Common Elements of Two Lists in C++
- Convert list into list of lists in Python
- Python - Convert List of lists to List of Sets
- Custom Multiplication in list of lists in Python
- Find frequency of given character at every position in list of lists in Python
- How to join list of lists in python?
- Program to find cost to reach final index of any of given two lists in Python
- Python - Column deletion from list of lists
- How do make a flat list out of list of lists in Python?
- Program to find number of minimum steps to reach last index in Python
- Python Program to find the cube of each list element
- Checking triangular inequality on list of lists in Python