Python min()
is a built-in function that returns the minimum value among the arguments supplied to the function. If an iterable is passed as the argument, the smallest item in the iterable is returned.
min (num1, num2, *args[, key])
Where,
There can be any number of objects supplied as arguments for comparison.
min(iterable, *[, key, default])
Where,
ValueError
will be raised.When an iterable is passed as the argument, the smallest item of the iterable is returned. If multiple iterables are passed then, the list for which the key function return smaller value is returned.
>>> min(1,2,3,4)
1
>>> py_num = [3,5,7,9]
>>> min(py_num)
3
def findMin(num):
rem = 0
while(num):
rem = num%10
return rem
# using min(arg1, arg2, *args, key)
print('Number with min remainder is:', min(11,48,33,17,19, key=findMin))
# using min(iterable, key)
num = [12,48,33,17]
print('Number with min remainder is:', min(num, key=findMin))
When executed, this will yield following output.
Number with min remainder is: 11 Number with min remainder is: 42