python,from mrjob.job import MRJob,,class MRWordCount(MRJob):,, def mapper(self, _, line):, for word in line.split():, yield (word, 1),, def reducer(self, key, values):, yield (key, sum(values)),,if __name__ == '__main__':, MRWordCount.run(),
`,,这个代码定义了一个MapReduce作业,mapper
函数将输入行拆分成单词,并为每个单词生成一个键值对(单词, 1)。reducer
函数则将所有相同单词的值相加,得到每个单词的总出现次数。Powered By Z-BlogPHP 1.7.3