programming-examples/python/Input_Output/Python program to count the frequency of words in a file.py

6 lines
212 B
Python
Raw Normal View History

2019-11-15 12:59:38 +01:00
from collections import Counter
def word_count(fname):
with open(fname) as f:
return Counter(f.read().split())
print("Number of words in the file :",word_count("test.txt"))