【发布时间】:2023-02-03 13:00:06
【问题描述】:
官方Pydoop tutorial里面有一个字数统计的例子。
我了解它是如何工作的,但我想知道 map(int, icounts)) 的内部工作原理。
我是否正确地理解了 icounts 是 1 的列表? int 从哪里来,为什么要映射?
# Compute the word frequency
import pydoop
def mapper(_, text, writer):
for word in text.split():
writer.emit(word, "1")
def reducer(word, icounts, writer):
writer.emit(word, sum(map(int, icounts)))
【问题讨论】: