Find Minimum Value From a List in Python (2D List)
February 21, 2013 Leave a comment
The following code can be used to find out the minimum value from a two dimensional list or an array as we call it in many programming languages.
def minimum1d(list):
x = list[0]
for i in list:
if i<x:
x=i
return x
def minimum2d(list):
x = list[0][0]
for i in list:
y=minimum1d(i)
if y<x:
x=y
return x
list=[[25,7,8],[61,5,9],[31,3,5]]
print(list)
print(minimum2d(list))
Note that same could have been done by using two nested “for” loops.
If you have any question you can leave a comment below ![]()