Map减少将mapper作为字典的输出传递给redu

2024-09-26 22:07:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我的mapper python脚本将输出生成为[2323223,[{'word':'hi'},{'charcount':'2'}] 在输出中,2323223是键,其余都是键2323223的值,但同样在值中,字典中有多个键值对。在

我的mapper脚本的一部分:

 analysis = {}
 wordanalysis = {}
 found = True

 for line in sys.stdin:
 (n1,n6) = re.split("\t+",line.strip())
 #n6 are the words and n1 is id
 words= re.split("\s+", n6.strip().lower())


 for i in range(0, len(words)):
  #adding id to a dictionary
   #n1 is id
    analysis[n1] = wordanalysis
    wordanalysis["word"] = words[i]
    wordanalysis["charcount"]= len(words[i])

    if len(words[i]) > 7:
       wordanalysis["longword"] = found
    else:
       wordanalysis["longword"] = not(found)

差不多吧。我的减速机应该像数单词一样,但是它将如何解释已经存在的字典。。如减速器: 对于线路输入标准输入:

映射器输出:

^{pr2}$

这是我的输出。我将这个值从mapper脚本传递到reducer脚本。减速机以上述o/p为输入,进行字符总数等数据分析。你知道怎么做吗?
主要的挑战是从mapper输出中获取dict值,以及如何根据dict中的键检索它们

谢谢


Tags: 脚本idforlen字典lineanalysisword

热门问题