write a python program to count the frequency of words in a file
Answers
Answered by
3
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}")
Similar questions
India Languages,
2 months ago
India Languages,
2 months ago
Math,
2 months ago
Math,
4 months ago
Math,
9 months ago
English,
9 months ago