Python实现一个最简单的MapReduce编程模型WordCount

版权声明:本文为博主原创文章,欢迎转载,请注明出处 https://blog.csdn.net/mouday/article/details/84641171

MapReduce编程模型:

  • Map:映射过程
  • Reduce:合并过程

import operator
from functools import reduce

# 需要处理的数据
lst = [
    "Tom",
    "Jack",
    "Mimi",
    "Jiji",
    "GoodMan"
]

# map过程:对每个数据进行处理,映射为字符串长度
lst = map(len, lst)
print(lst)  # <map object at 0x101b43c18>


# reduce过程:对所有map处理过的数据进行汇总
result = reduce(operator.add, lst)

print(result)  # 22

猜你喜欢

转载自blog.csdn.net/mouday/article/details/84641171
今日推荐