Write a method/function COUNTTOTHE( ) to count the words "to" and "the" present in
a text file "Poem.txt".
Answers
Answered by
2
def COUNTTOTHE(file):
keys = ["to_count", "the_count"]
with open(file) as f:
words = f.read().split()
to_count, the_count = words.count("to"), words.count("the")
return dict(zip(keys, [to_count, the_count]))
for k, v in COUNTTOTHE("Poem.txt").items():
print(f"{k}: {v}")
Similar questions