I am trying to find the count of words that occured in a file. I have a text file (TEST.txt) the content of the file is as follows:
TEST.txt
ashwin prog
Use the update method of Counter. Example:
update
from collections import Counter data = '''\ ashwin programmer india amith programmer india''' c = Counter() for line in data.splitlines(): c.update(line.split()) print(c)
Output:
Counter({'india': 2, 'programmer': 2, 'amith': 1, 'ashwin': 1})