在官方的Pydoop tutorial中有一个字数统计的例子。
我理解它是如何工作的,但我想知道map(int, icounts))
的内部工作原理。
icounts是一个1的列表,我理解对了吗?int从哪里来,为什么map?
# 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)))
1条答案
按热度按时间du7egjpx1#
像
int
这样的类型可以作为函数应用于值,以将该值转换为整数(如果它支持该转换)。例如:
示例中的
icounts
很可能是字符串值的可迭代对象(类似于列表),在其上Mapint
会将其转换为整数值的可迭代对象。