Minimum in list python by R4R Team

Example -

mylist=[14,5,2,8,3,10,3,45,23,34]
then minimum in this list is 2

program -

print("Enter all element in list")
l=list(map(int,input().split()))

#first way
minimum=l[0]
for i in range(len(l)):
if minimum>l[i]:
minimum=l[i]
print("Minimum in list is "+str(minimum))

#second way
print("Minimum in list is "+str(min(l)))


output -

Enter all element in list
9 12 14 76 3 2
Minimum in list is 2
Minimum in list is 2


program to do this in a single line -

print(str(min(list(map(int,input("Enter number in listn").split()))))+" is minimum")


output -

Enter number in list
1 2 3 4 5
1 is minimum


In this program, we done this in one line and that's the beauty of the python programming language. How it works ? Firstly we take string input then with the use of split() we seprate the number then using map we type cast the string number to integer number then list is created then min() function is find the minimum out of them and print() function display that.

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!