- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Read a List of Words and Return the Length of the Longest One
When it is required to read a list of words and return the length of the longest list, a method can be defined that iterates through the list and gets the length of every string in the list of strings using the ‘len’ method.
Below is a demonstration of the same −
Example
def longest_length_string(my_string): len_str = len(my_string[0]) temp_val = my_string[0] for i in my_string: if(len(i) > len_str): len_str = len(i) temp_val = i print("The word with the longest length is:", temp_val, " and length is ", len_str) my_string = ["three", "Jane", "quick", "lesson", 'London', 'newyork'] print("The list is :") print(my_string) print("The method to find the longest string in the list is called") longest_length_string(my_string)
Output
The list is : ['three', 'Jane', 'quick', 'lesson', 'London', 'newyork'] The method to find the longest string in the list is called The word with the longest length is: newyork and length is 7
Explanation
A method named ‘longest_length_string’ is defined.
It takes a list of strings as a parameter.
The list is iterated over, and the length of every string in the list is determined.
The largest of these values is determined and returned as output.
A list of strings is defined and is displayed on the console.
The method is called bypassing this list as a parameter.
The output is displayed on the console.
- Related Articles
- Python Program to return the Length of the Longest Word from the List of Words
- Program to find length of longest interval from a list of intervals in Python
- Program to find length of longest arithmetic subsequence of a given list 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 length of longest contiguous sublist with same first letter words in Python
- Find and return the longest length of set in JavaScript
- Program to find length of longest sign alternating subsequence from a list of numbers in Python
- Program to find length of longest matrix path length in Python
- Program to find out the length of longest palindromic subsequence using Python
- Python Program to Find the Length of a List Using Recursion
- Python program to sort a List according to the Length of the Elements?
- Program to find length of longest balanced subsequence in Python
- Program to find length of longest anagram subsequence in Python
- Program to find length of longest consecutive sequence in Python

Advertisements