Skip to content

Commit 122b2b8

Browse files
committed
单词计数 (Map Reduce版本)
1 parent 8f2cd32 commit 122b2b8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

word_count_map_reduce.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class WordCount:
2+
3+
# @param {str} line a text, for example "Bye Bye see you next"
4+
def mapper(self, _, line):
5+
# Write your code here
6+
# Please use 'yield key, value'
7+
words = line.split()
8+
for word in words:
9+
yield word, 1
10+
11+
12+
# @param key is from mapper
13+
# @param values is a set of value with the same key
14+
def reducer(self, key, values):
15+
# Write your code here
16+
# Please use 'yield key, value'
17+
yield key, len(values)

0 commit comments

Comments
 (0)