title: Least common words in a file
body: <p>I am interested in finding least common occurring text in a file.</p>
  
  <pre><code>from collections import Counter
  
  # Load the file and extract the words
  lines = open("mobydick.txt").readlines()
  words = [ word for l in lines for word in l.rstrip().split() ]
  print 'No of words in the file:', len(words)
  
  # Use counter to get the counts
  counts = Counter( words )
  
  print 'Least common words:'
  for word, count in sorted(counts.most_common()[:-3], key=lambda (word, count): (count, word), reverse=True):
      print '%s %s' % (word, count)
  </code></pre>
  
  <p>How do I limit just 3 words. It prints a bunch.</p>