Find the count of the words in the text file using python -


this question has answer here:

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 
  1. now need read file using python , need find count of each , every word
  2. 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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -