programming-examples/python/Input_Output/Python program to find the longest words.py
2019-11-15 12:59:38 +01:00

7 lines
262 B
Python

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'))