[Type C]Q5. Write a short python code segment that prints the longest word in the list of words.

The len() function returns the number of items in an object.

When the object is a string, the len() function returns the number of characters in the string.

Program code:

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in

Output:

Longest word present in list is: ComputerTutor

Sort the list based on length of the words and then after all iterations print the word at the first position in the list.

Another approach is initiating for loop and iterating it for all elements in the list and the word with the greatest length is printed.

Basic python functionality is demonstrated in above program.

To view all the lessons in chapter 1: http://computertutor.in/class-12-computer-science/chapter-2/

To view entire class 12 computer science study material: http://computertutor.in/resources/

You cannot copy content of this page