min(arg1,arg2, key=my_fun )
arg1, arg2 :numbers , iterable inputs or more than one inputs x=6
y=9
print(min(x,y)) # 6
Using list
my_list=[6,1,2,3,4,5]
print(min(my_list)) # 1
my_list=['Hello','Welcome','To','Plus2net']
print(min(my_list)) # Hello
my_list=['hello','Welcome','to','plus2net']
print(min(my_list)) # Welcome
Using Dictionarymy_dict={1:'A',2:'B',3:'C'}
print(min(my_dict)) # 1
Getting lowest t key value pair based on value of the dictionarymy_dict={'Raju':45,'Ronn':56,'Tom':50}
key_of_min_value = min(my_dict, key=my_dict.get)
print(key_of_min_value,my_dict[key_of_min_value])
Output is here
Raju 45
We will use tuplemy_tuple=(6,1,12,7)
print(min(my_tuple)) #1
Using more than one list
my_list1=[5,1,1]
my_list2=[6,1,-3]
print(min(my_list2,my_list1)) # [5, 1, 1]
More than two lists
my_list1=[4,7,8,9]
my_list2=[5,1,1]
my_list3=[6,1,-3]
print(min(my_list2,my_list1,my_list3)) # [4, 7, 8, 9]
Here comparison is done from left to right and based on the position of the first lowest element the list is returned ( by min() ) as minimum. my_list1=[4,7,8,9]
my_list2=[4,1,1]
my_list3=[4,1,-3]
print(min(my_list2,my_list1,my_list3)) # [4, 1, -3]
my_list1=[4,2,3,7,8]
my_list2=[5,1,50]
print(min(my_list2,my_list1,key=sum)) # [4, 2, 3, 7, 8]
Using Len
my_list1=[4,2,3,7,8]
my_list2=[5,1,50]
print(min(my_list2,my_list1,key=len)) # [5, 1, 50]
def last_digit(my_list):
return my_list[-1] # last digit
my_list1=[4,2,3,7,8,9]
my_list2=[25,41,1]
print(min(my_list2,my_list1,key=last_digit)) #[25, 41, 1]
max()
Iterator
any()
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.