Find the count of the words in the text file using python -
this question has answer here:
- python - find occurrence of word in file 5 answers
i had text file named content_data
following content
a house house must beautiful house , never regrets regrets baloon in baloons. find words must repeated words in file of house , ballons
- now need read file using python , need find count of each , every word
we need implement result in form of dictionary below format
{'house':4,'baloon':3,'in':4........},
i mean in format of
{word:count}
can please let me know how this
from collections import counter string import punctuation counter = counter() open('/tmp/content_data') f: line in f: counter.update(word.strip(punctuation) word in line.split()) result = dict(counter) # note: because have # isinstance(counter, dict) # may leave result counter object print result
Comments
Post a Comment