Skip to content
Related Articles

Related Articles

Improve Article
Python | Max/Min value in Nth Column in Matrix
  • Last Updated : 30 Dec, 2020

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 way in which this task can be performed.

Method : Using max()/min() + zip()
This task can be solved using the combination of above functions. In this, we pass in the zip() the list, to access all columns and max()/min() to get maximum or minimum of columns.




# Python3 code to demonstrate working of
# Max value in Nth Column in Matrix
# using max() + zip()
  
# initialize list
test_list = [[5, 6, 7],
             [9, 10, 2], 
             [10, 3, 4]]
  
# printing original list
print("The original list is : " + str(test_list))
  
# initialize N 
N = 2
  
# Max value in Nth Column in Matrix
# using max() + zip()
res = [max(i) for i in zip(*test_list)][N] 
  
# printing result
print("Max value of Nth column is : " + str(res))
Output :
The original list is : [[5, 6, 7], [9, 10, 2], [10, 3, 4]]
Max value of Nth column is : 7

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :