0

Python min function with *args

How can i find the minimum number in a list by passing them to my own function. def myfunc(a,*b): ..........

7th Aug 2021, 8:08 AM
sid
sid - avatar
7 Answers
+ 10
sid , as we don't know what your function will receive as arguments and what the function is doing exactly (? only finding the min nunbers ?), please post the complete code, and also a complete task description. â–Șin general: for finding the min number of a list, you don't need to use *args. just use: def myfunc(the_list) .....
7th Aug 2021, 8:17 AM
Lothar
Lothar - avatar
+ 7
No need to declare x in the function. Just declare *y and then use a for loop to iterate and return the minimum value. Maybe your want like this: https://code.sololearn.com/cYzdRU49Gb0U
7th Aug 2021, 8:36 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 5
Do you mean something like this? https://code.sololearn.com/c63RYk5iMq3q
7th Aug 2021, 8:15 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 5
If you want the function to return <x> when there's nothing in <y> having value less than <x>, without using built-in function def my_min(x, *y): for v in y: if v < x: x = v return x print(my_min(8, 13, 4, 42, 120, 7))
7th Aug 2021, 9:17 AM
Ipang
+ 2
Lothar def my_min(x, *y): if x < y: return x else: return y print(my_min(8, 13, 4, 42, 120, 7)) The given code defined a function called my_min(), which takes two arguments and returns the smaller one. I need to improve the function, so that it can take any number of variables, so that the function call works.
7th Aug 2021, 8:29 AM
sid
sid - avatar
+ 1
The future is now thanks to science[In a break] i have to find the minimum using my own,not with inbuilt min()
7th Aug 2021, 8:27 AM
sid
sid - avatar
+ 1
def get_min(*args): if all([type(i) is int for i in args]): return min(args) else: return "wrong type of item in list"
7th Aug 2021, 9:50 AM
Shadoff
Shadoff - avatar