title: How to count one specific word in Python?
body: <p>I want to count a specific word in the file.</p>
  
  <p>For example how many times does 'apple' appear in the file.
  I tried this:</p>
  
  <pre><code>#!/usr/bin/env python
  import re 
  
  logfile = open("log_file", "r") 
  
  wordcount={}
  for word in logfile.read().split():
      if word not in wordcount:
          wordcount[word] = 1
      else:
          wordcount[word] += 1
  for k,v in wordcount.items():
      print k, v
  </code></pre>
  
  <p>by replacing 'word' with 'apple', but it still counts all possible words in my file.</p>
  
  <p>Any advice would be greatly appreciated. :)</p>