16
loading...
This website collects cookies to deliver better user experience
min(iterable, *iterables, key, default)
min(arg1, arg2, *args, key)
languages = ["Spanish", "English", "French", "Italian"]
small_string = min(languages)
print("The smallest string in languages is:", small_string)
The smallest string in languages is: English
num = [3, -2, 1, 15, 10, 0.6]
small_num = min(num)
print("The smallest number is:", small_num)
The smallest number is: -2
sample_dict = {1: 2, 3: 4, -5: 6, -7: 8}
# finding the smallest key
key_one = min(sample_dict)
print("The smallest key in sample_dict is:", key_one)
# finding the key whose value is the smallest
key_two = min(sample_dict, key = lambda k: sample_dict[k])
print("The key with the smallest value in sample_dict:", key_two)
# getting the smallest value
print("The smallest value found is:", sample_dict[key_two])
The smallest key in sample_dict is: -7
The key with the smallest value in sample_dict: 1
The smallest value found is: 2
print(min(2, -1.0, 30, -9))
print(min("f", "l", "e", "x", "i"))
print(min(7.14, -1.12, 7.66))
-9
e
-1.12
print(min([])) # here the empty iterable causes ValueError
# The solution
print(min([], default=0)) #negating the error with default value
list_one = [11,12,13]
list_two = [2, 4, 6, 8, 10, 12]
min_val = min(list_one, list_one, key = len)
print("The minimum value : ", min_val)
The minimum value : [11, 12, 13]