Write a function that counts and display the number of 5 letter words in a
text file “Sample.txt"
Answers
Answered by
9
Answer:
It goes like:
Answered by
3
def count(file):
with open(file) as f:
words = [word for line in f for word in line.split()]
five_letter_words = [word for word in words if len(word) == 5]
print("\n".join(five_letter_words))
return f"No of 5 letter words is {len(five_letter_words)}"
print(count("sample.txt"))
Similar questions