Find Minimum Value From a List in Python (2D List)

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 :)

About these ads

About b4blogger
I am a student and a blogger who wants to share my knowledge with the world.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: