-
Notifications
You must be signed in to change notification settings - Fork 1
/
reducer_p1q1.py
executable file
·46 lines (31 loc) · 992 Bytes
/
reducer_p1q1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python
import sys
salesTotal = 0
oldKey = None
# Loop around the data
# It will be in the format key\tval
# Where key is the store name, val is the sale amount
#
# All the sales for a particular store will be presented,
# then the key will change and we'll be dealing with the next store
for line in sys.stdin:
data_mapped = line.strip().split("\t")
if len(data_mapped) != 2:
# Something has gone wrong. Skip this line.
continue
thisKey, thisSale = data_mapped
if oldKey and oldKey != thisKey:
print oldKey, "\t", salesTotal
oldKey = thisKey
salesTotal = 0
oldKey = thisKey
salesTotal += float(thisSale)
if oldKey != None:
print oldKey, "\t", salesTotal
"""
Instead of breaking the sales down by store, give us a sales breakdown
by prduct category across all of our stores.
What is the value of total sales for the following categories?
Toys: 57463477.11
Consumer Electronics: 57452374.13
"""