programming-examples/python/Input_Output/Python program to find the longest words.py

7 lines
262 B
Python
Raw Normal View History

2019-11-15 12:59:38 +01:00
def longest_word(filename):
with open(filename, 'r') as infile:
words = infile.read().split()
max_len = len(max(words, key=len))
return [word for word in words if len(word) == max_len]
print(longest_word('test.txt'))