title: Most frequent word in one file which is not found in another file using Python
body: <p>I am trying to write a program where I count the most frequently used words from one file but those words should not be available in another file. So basically I am reading data from test.txt file and counting the most frequently used word from that file, but that word should not be found in test2.txt file. </p>
  
  <p>Below are sample data files, test.txt and test2.txt</p>
  
  <p>test.txt: </p>
  
  <pre><code>The Project is for testing. doing some testing to find what's going on. the the the.
  </code></pre>
  
  <p>test2.txt: </p>
  
  <pre><code>a
  about
  above
  across
  after
  afterwards
  again
  against
  the
  </code></pre>
  
  <p>Below is my script, which parses files test.txt and test2.txt. It finds the most frequently used words from test.txt, excluding words found in test2.txt. </p>
  
  <p>I thought I was doing everything right, but when I execute my script, it gives "the" as the most frequent word. But actually, the result should be "testing", as "the" is found in test2.txt but "testing" is not found in test2.txt.</p>
  
  <pre><code>from collections import Counter
  import re
  
  dgWords = re.findall(r'\w+', open('test.txt').read().lower())
  
  f = open('test2.txt', 'rb')
  sWords = [line.strip() for line in f]
  
  print(len(dgWords));
  
  for sWord in sWords:
      print (sWord)
      print (dgWords) 
      while sWord in dgWords: dgWords.remove(sWord)   
  
  print(len(dgWords));
  mostFrequentWord = Counter(dgWords).most_common(1)
  print (mostFrequentWord)
  </code></pre>