Skip to content

Instantly share code, notes, and snippets.

@heynemann
Created August 13, 2012 14:50
Show Gist options
  • Save heynemann/3341423 to your computer and use it in GitHub Desktop.
Save heynemann/3341423 to your computer and use it in GitHub Desktop.
r3 sample reducer
#!/usr/bin/python
# -*- coding: utf-8 -*-
from collections import defaultdict
class CountWordsReducer:
job_type = 'count-words'
def reduce(self, app, items):
word_freq = defaultdict(int)
for line in items:
for word, frequency in line:
word_freq[word] += frequency
return word_freq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment