title: Function to count repeated words in a text file? (Python)
body: <p>Here is the question below: </p>
  
  <p>Question 12</p>
  
  <p>Write a function named repeatWords(). The function repeatWords() takes two string parameters:
  the name of an input file and the name of an output file. The input file contains only lower case
  letters and white space.
  The function repeatWords() should identify the word(s) that appear more than once in the file
  and write each such word to a line of the output file, followed by the number of times that the
  word appears. A repeated word should be written to only a single line of the output file, no matter
  how many times it appears in the input file. The order that the words are written to the output file
  does not matter.
  For example, if the input file contains the following lines:</p>
  
  <p><code>i would not like them here or there</code></p>
  
  <p><code>i would not like them anywhere</code></p>
  
  <p>Then an output file with the following lines would be correct:</p>
  
  <p><code>like 2</code></p>
  
  <p><code>not 2</code></p>
  
  <p><code>i 2</code></p>
  
  <p><code>would 2</code></p>
  
  <p><code>them 2</code></p>
  
  <p>Here is my code. I just don't know how to get an if statement when it comes to finding if a number in the counter is greater than 1(greater or equal than 2).</p>
  
  <pre><code>def repeatWords(inFile, outFile):
  from collections import Counter
  outFile = open(outFile, 'w')
  with open(inFile, 'r') as f:
      wordcount = Counter(f.read().split())
      for item in wordcount.items():
          if item &gt;= 2:
              outFile.write("{} {}".format(*item))
  print(repeatWords('input.txt','output.txt'))
  </code></pre>
  
  <p>Also I did not start the part in the code yet where I have to count only the repeated words</p>