Computer Science, asked by ritika5456, 4 months ago

Write a method/function COUNTTOTHE( ) to count the words "to" and "the" present in

a text file "Poem.txt".​

Answers

Answered by jai696
2

\huge\red{\mid{\fbox{\tt{Using\: Python\: 3}}\mid}}

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}")

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Similar questions