Last active
August 29, 2015 13:56
-
-
Save AndreaCatalucci/9227823 to your computer and use it in GitHub Desktop.
reducer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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