python统计《论语》里的词频
利用jieba库统计《论语》里的词频
#CalLunyuV1.py
import jieba
txt = open("lunyu.txt", "r", encoding = "utf-8").read()
words = jieba.lcut(txt)
counts = {
   }
for word in words:
    if len(word) ==1:
        continue
    else:
        counts[word] = counts.get(word,0) +1
items = list(counts.items())
items.sort(key=lambda x:x[1],reverse=True)
for i in range(15):
    word, count = items[i]
    print("{0:<10}{1:>5}".format(word,count))
结果显示
 君子 63
 孔子 34
 子路 34
 可以 25
 夫子 23
 仁者 22
 何如 20
 可谓 19
 子贡曰 18
 不知 16
 小人 15
 不可 15
 颜渊 15
 子贡 12
 不能 12
结果说明:君子是孔子及门徒经常强调的概念,子路是和孔子交往频次最多的,其次是子贡和颜渊。
 投递中国邮政储蓄银行等公司10个岗位
投递中国邮政储蓄银行等公司10个岗位 查看21道真题和解析
查看21道真题和解析