Skip to content

Instantly share code, notes, and snippets.

@AndreaCatalucci
Last active August 29, 2015 13:56
Show Gist options
  • Save AndreaCatalucci/9227823 to your computer and use it in GitHub Desktop.
Save AndreaCatalucci/9227823 to your computer and use it in GitHub Desktop.
reducer.py
import sys
def reducer():
sales_total = 0
old_key = None
for line in sys.stdin:
data = line.strip().split("\t")
if len(data) !=2
continue
key, sales = data
if (key and key != old_key):
print "{0}\t{1}".format(old_key, sales_total)
sales_total = 0
old_key = key
sales_total += float(sales)
print "{0}\t{1}".format(key, sales_total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment