Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

count the frequency of words in a file

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"))
 
PREVIOUS NEXT
Tagged: #count #frequency #words #file
ADD COMMENT
Topic
Name
9+6 =