中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Python 的mapreduce 單詞統(tǒng)計(jì)

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線(xiàn)!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
#!/usr/bin/env python
import random
 
# 'abc..z'
alphaStr = "".join(map(chr, range(97,123)))
fp = open("word.txt", "w")
maxIter = 100000
for i in range(maxIter):
    word = ""
    len =random.randint(1,5)
    for j in range(len):
        word + = alphaStr[random.randint(0,25)]
        fp.write(word + '\n')
fp.close()
 
 
cat word.txt | ./wordcount_mapper.py | ./wordcount_reducer.py .
 
word count reduce,   python
 
#filename:  wordcount_reducer.py
from  operator import itemgetter
import sys
 
wordcount = {}
for line in sys.stdin:
    word, count = line.strip().split('\t',1)
    try:
        count = int(count)
        wordcount[word] = wordcount.get(word,0) + count
    except ValueError
        pass
 
sorted_wordcount = sorted(wordcount.iterms(), key = itemgettter(0))
for word,count in sorted_wordcount:
    print("%s\t%s") %(word, count)

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:python批量抓取美女圖片

下一篇:Java唯一碼生成