CBSE Class 12 Computer Science
Question 98 of 105
Python Revision Tour II — Question 5
Back to all questions 5
Question Write a short python code segment that prints the longest word in a list of words.
my_list = eval(input("Enter the list : "))
longest_word = ""
max_length = 0
for word in my_list:
if len(word) > max_length:
max_length = len(word)
longest_word = word
print("Longest word:", longest_word)Enter the list : ['red', 'yellow', 'green', 'blue']
Longest word: yellow
Enter the list : ['lion', 'elephant', 'tiger', 'monkey', 'hippopotamus']
Longest word: hippopotamus