Python Program to Find Longest Word From Sentence or Text
In this program, first we read
sentence from user then we use string
split() function to convert it to list. After splitting it is passed to
max() function with keyword argument
key=len which returns longest word from sentence.
This Python program finds longest word from a given text or sentence.
Python Source Code: Longest Word
# Longest word # Reading sentence from user sentence = input("Enter sentence: ") # Finding longest word longest = max(sentence.split(), key=len) # Displaying longest word print("Longest word is: ", longest) print("And its length is: ", len(longest))
Enter sentence: Tongue tied and twisted just an earth bound misfit I Longest word is: twisted And its length is: 7