title: To count the word frequency in multiple documents python
body: <p>I have a list of the addresses of multiple text files in a dictionary 'd':</p>
  
  <pre><code>'d:/individual-articles/9.txt', 'd:/individual-articles/11.txt', 'd:/individual-articles/12.txt',...
  </code></pre>
  
  <p>and so on...</p>
  
  <p>Now, I need to read each file in the dictionary and keep a list of the word occurrences of each  and every word that occurs in the entire dictionary.</p>
  
  <p>My output should be of the form:</p>
  
  <pre><code>the-500
  
  a-78
  
  in-56
  </code></pre>
  
  <p>and so on..</p>
  
  <p>where 500 is the number of times the word "the" occurs in all the files in the dictionary..and so on..</p>
  
  <p>I need to do this for all the words.</p>
  
  <p>I am a python newbie..plz help!</p>
  
  <p>My code below doesn't work,it shows no output!There must be a mistake in my logic, please rectify!!</p>
  
  <pre><code>import collections
  import itertools
  import os
  from glob import glob
  from collections import Counter
  
  
  
  
  folderpaths='d:/individual-articles'
  counter=Counter()
  
  
  filepaths = glob(os.path.join(folderpaths,'*.txt'))
  
  
  
  
  folderpath='d:/individual-articles/'
  # i am creating my dictionary here, can be ignored
  d = collections.defaultdict(list)
  with open('topics.txt') as f:
      for line in f:
         value, *keys = line.strip().split('~')
          for key in filter(None, keys):
              if key=='earn':
                 d[key].append(folderpath+value+".txt")
  
     for key, value in d.items() :
          print(value)
  
  
  word_count_dict={}
  
  for file in d.values():
      with open(file,"r") as f:
          words = re.findall(r'\w+', f.read().lower())
          counter = counter + Counter(words)
          for word in words:
              word_count_dict[word].append(counter)              
  
  
  for word, counts in word_count_dict.values():
      print(word, counts)
  </code></pre>