Longest Word in Dictionary
Question
Given a list of strings, find the longest word in the list that is a valid word in the English dictionary.
Example 1
None
Solution
- ▭
- ▯
all//Longest Word in Dictionary.py
def longest_word_in_dictionary(words):
longest_word = ""
for word in words:
if len(word) > len(longest_word):
longest_word = word
return longest_word
words = ["Python", "is", "a", "very", "powerful", "programming", "language"]
print(longest_word_in_dictionary(words))
all//Longest Word in Dictionary.py
def longest_word_in_dictionary(words):
longest_word = ""
for word in words:
if len(word) > len(longest_word):
longest_word = word
return longest_word
words = ["Python", "is", "a", "very", "powerful", "programming", "language"]
print(longest_word_in_dictionary(words))