我是靠谱客的博主 着急小蝴蝶,这篇文章主要介绍用python对《三国演义》的人物出场进行统计,现在分享给大家,希望可以做个参考。

import jieba
txt = open("三国演义.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))

最后

以上就是着急小蝴蝶最近收集整理的关于用python对《三国演义》的人物出场进行统计的全部内容,更多相关用python对《三国演义》内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(148)

评论列表共有 0 条评论

立即
投稿
返回
顶部