Skip to content

Commit 248d793

Browse files
committed
Create wordCount.py
1 parent 233e5f4 commit 248d793

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

wordCount.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import MapReduce
2+
import sys
3+
4+
"""
5+
Word Count Example in the Simple Python MapReduce Framework
6+
"""
7+
8+
mr = MapReduce.MapReduce()
9+
10+
# =============================
11+
# Do not modify above this line
12+
13+
def mapper(record):
14+
# key: document identifier
15+
# value: document contents
16+
key = record[0]
17+
value = record[1]
18+
words = value.split()
19+
for w in words:
20+
mr.emit_intermediate(w, 1)
21+
22+
def reducer(key, list_of_values):
23+
# key: word
24+
# value: list of occurrence counts
25+
total = 0
26+
for v in list_of_values:
27+
total += v
28+
mr.emit((key, total))
29+
30+
# Do not modify below this line
31+
# =============================
32+
if __name__ == '__main__':
33+
inputdata = open(sys.argv[1])
34+
mr.execute(inputdata, mapper, reducer)

0 commit comments

Comments
 (0)