title: counting duplicate words in python the fastest way
body: <p>I was trying to count duplicate words over a list of 230 thousand words.I used python dictionary to do so. The code is given below:</p>
  
  <pre><code>for words in word_list:
      if words in word_dict.keys():
         word_dict[words] += 1
      else:
         word_dict[words] = 1
  </code></pre>
  
  <p>The above code took 3 minutes!. I ran the same code over 1.5 million words and it was running for more than 25 minutes and I lost my patience and terminated. Then I found that I can use the following code from <a href="https://stackoverflow.com/questions/3496518/python-using-a-dictionary-to-count-the-items-in-a-list">here</a> (also shown below). The result was so surprising, it completed within seconds!. So my question is what is the faster way to do this operation?. I guess the dictionary creation process must be taking O(N) time. How was the Counter method able to complete this process in seconds and create an exact dictionary of word as key and frequency as it's value?</p>
  
  <pre><code>from collections import Counter
  word_dict = Counter(word_list)
  </code></pre>