

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to return the Length of the Longest Word from the List of Words
When it is required to return the length of the longest word from a list of words, a method is defined that takes a list as parameter. It checks if an element is in the list and depending on this, the output is displayed.
Example
Below is a demonstration of the same
def find_longest_length(my_list): max_length = len(my_list[0]) temp = my_list[0] for element in my_list: if(len(element) > max_length): max_length = len(element) temp = element return max_length my_list = ["ab", "abc", "abcd", "abcde"] print("The list is :") print(my_list) print("The result is :") print(find_longest_length(my_list))
Output
The list is : ['ab', 'abc', 'abcd', 'abcde'] The result is : 5
Explanation
A method named ‘find_longest_length’ is defined that takes a list as parameter.
The length of the list is assigned to a variable.
The list is iterated over, and every element’s length is checked to see if it is greater than length of the first element of the list.
If so, this is assigned as the maximum length.
It is returned as output.
Outside the method, a list is defined and is displayed on the console.
The method is called by passing the required parameters.
The output is displayed on the console.
- Related Questions & Answers
- Python Program to Read a List of Words and Return the Length of the Longest One
- Python program to find word score from list of words
- C++ program for length of the longest word in a sentence
- Program to find length of longest diminishing word chain in Python?
- Program to find length of longest interval from a list of intervals in Python
- Find and return the longest length of set in JavaScript
- Python Program to Remove the nth Occurrence of the Given Word in a List where Words can Repeat
- Program to find length of longest word that can be formed from given letters in python
- Program to find length longest prefix sequence of a word array in Python
- Program to find length of longest Fibonacci subsequence from a given list in Python
- Program to find length of longest alternating subsequence from a given list in Python
- Program to find out the length of longest palindromic subsequence using Python
- Program to find length of longest sign alternating subsequence from a list of numbers in Python
- Python program to find the character position of Kth word from a list of strings
- PHP program to find the length of the last word in the string