python手动实现WorldCount
原创
©著作权归作者所有:来自51CTO博客作者练习生Tony的原创作品,请联系作者获取转载授权,否则将追究法律责任
str_test = 'the quick brown for jumps over the lazy dog.'
str_test = str_test.replace('.,!?、',"")
slist = str_test.split(" ")
def WordCounter(slist):
rstd = dict()
for i in slist:
if i in rstd.keys():
rstd[i] += 1
else:
rstd[i] = 1
return rstd
print("词频统计结果:",WordCounter(slist))
结果: