Back
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.
from __future__ import divisiona=[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)
from __future__ import division
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
def my_min_function(a):
min_value = None
for value in a:
if not min_value:
min_value = value
elif value < min_value:
return min_value
Want to learn more about Python! Come and Join:- Python course
For more details, do check out our tutorial,
31k questions
32.8k answers
501 comments
693 users