Skip to content

Commit e7e416c

Browse files
committed
Added missing P2Q3_Reducer.py file.
Thanks to @leebrian for the heads-up. I somehow missed out committing this file to GitHub.
1 parent 233b2c4 commit e7e416c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/python
2+
3+
# Write a MapReduce program which will display the number of hits for each different file on the Web site.
4+
5+
import sys
6+
7+
countTotal = 0
8+
oldKey = None
9+
10+
# Loop around the data
11+
# It will be in the format key\tval
12+
#
13+
14+
for line in sys.stdin:
15+
data_mapped = line.strip().split("\t")
16+
if len(data_mapped) != 2:
17+
# Something has gone wrong. Skip this line.
18+
continue
19+
20+
thisKey, thisCount = data_mapped
21+
22+
if oldKey and oldKey != thisKey:
23+
print oldKey, "\t", countTotal
24+
oldKey = thisKey;
25+
countTotal = 0
26+
27+
oldKey = thisKey
28+
countTotal += int(thisCount)
29+
30+
if oldKey != None:
31+
print oldKey, "\t", countTotal
32+

0 commit comments

Comments
 (0)