title: Mapreduce & Python: Bigrams
body: <p>I am looking to alter my map reduce files to output the top bigrams in a chunk of text instead of the word count, so both words and the bigram count</p>
  
  <p>This is my current code and approach.</p>
  
  <p>Map:</p>
  
  <pre><code>import sys
  
  for line in sys.stdin:
      line = line.strip()
      words = line.split()  #bigrams = line.split()
      for word in words:    #for bigram in words
          print '%s\t%s' % (word,1)  #print ... word pair???
  </code></pre>
  
  <p>Reduce:</p>
  
  <pre><code>mydict = dict() 
  for line in sys.stdin:
      (word,cnt) = line.strip().split('\t') #bigram and bigram count
      mydict[word] = mydict.get(word,0) 1
  
  for word,cnt in mydict.items():
      print word,cnt                      #print bigram and bigram count
  </code></pre>
  
  <p>Thank you. </p>
  
  <p>I saw nltk as a popular solution for computing bigrams, should I have that approach even in my mapreduce format?</p>