Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (16.4k points)

Let's say I have a list, I don't know how to find the minimum value from the list.

a=[1,67,8,3,42,510,261]

Now, From this list how can I find the min and max of this list using a function?

I don't want to use the inbuilt function.

1 Answer

0 votes
by (26.4k points)

from __future__ import division

a=[1,67,8,3,42,510,261] 

max_value = max(a)

min_value = min(a)

avg_value = 0 if len(somelist) == 0 else sum(somelist)/len(somelist)

If you want to find the minimum value manually as a function:

a=[1,67,8,3,42,510,261]

def my_min_function(a):

    min_value = None

    for value in a:

        if not min_value:

            min_value = value

        elif value < min_value:

            min_value = value

    return min_value

Want to learn more about Python! Come and Join:- Python course

For more details, do check out our tutorial,

Related questions

0 votes
4 answers
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...