Python Program to Find Shortest Word From Sentence or Text


In this program, first we read text from user then we use string split() function to convert it to list. After splitting, it is passed to min() function with keyword argument key=len which returns shortest word from text or sentence. And this can be done in one line.


This Python program finds Shortest word from a given text or sentence.


Python Source Code: Shortest Word


# Shortest word

# Reading text from user

text = input("Enter some text: ")

# Finding longest word
shortest = min(text.split(), key=len)

# Displaying longest word
print("Shortest word is: ", shortest)
print("And its length is: ", len(shortest))

Output

Enter some text: Tongue tied and twisted just an earth bound misfit I
Shortest word is:  I
And its length is:  1