Last active
October 1, 2020 01:49
-
-
Save a4vg/c0c5fb7f807a4a199b8d6c496900ef61 to your computer and use it in GitHub Desktop.
Mapper and reducer
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 | |
for line in sys.stdin: | |
data = line.strip().split("\t") | |
date, time, store, category, cost, payment = data | |
print store,"\t",cost |
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 | |
maxStore = {} | |
for line in sys.stdin: | |
data = line.strip().split("\t") | |
if len(data) != 2: | |
continue | |
category, sales = data | |
sales = float(sales) | |
if category in maxStore: | |
if maxStore[category] < float(sales): | |
maxStore[category] = float(sales) | |
else: | |
maxStore[category] = float(sales) | |
for category, sales in maxStore.iteritems(): | |
print "{0}\t{1}".format(category, sales) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment