Skip to content

Instantly share code, notes, and snippets.

@a4vg
Last active October 1, 2020 01:49
Show Gist options
  • Save a4vg/c0c5fb7f807a4a199b8d6c496900ef61 to your computer and use it in GitHub Desktop.
Save a4vg/c0c5fb7f807a4a199b8d6c496900ef61 to your computer and use it in GitHub Desktop.
Mapper and reducer
import sys
for line in sys.stdin:
data = line.strip().split("\t")
date, time, store, category, cost, payment = data
print store,"\t",cost
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