Find smallest word in string in python by R4R Team

Example-

string is "This is the string"
here smallest word is "is"


program-

import functools

print("Enter string")
s=input()

l=s.split()

def func(x,y):
if len(x)<'len(y):
return x
else:
return y

x=functools.reduce(func,l)
print("Smallest Word is :",x)


output-

Enter string
This is string
Smallest Word is : is


-In this program, we take a input of string then we split this string into the list, then we use reduce() function which check two words by func() function and return min length word, and at last we have a one word with minimum length.




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!