Computer Science, asked by ghumankomalpreet1, 4 months ago

write a python program to count the frequency of words in a file​

Answers

Answered by jai696
3

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

def word_frequency(file):

with open(file) as f:

words = [word for line in f for word in line.split()]

return {word: words.count(word) for word in words}

for k, v in word_frequency("file.txt").items():

print(f"{k}: {v}")

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

Similar questions