jieba分词之聊斋

import jieba
excludes = {"不知","不可","一日","不敢","数日","以为","不能","可以","不得","如此","------------","三日","而已","明日","其中","未几","二人","一人"}
txt = open("liao.txt", "r", encoding='utf-8').read()
words = jieba.lcut(txt)
counts = {}
for word in words:
if len(word) == 1:
continue
elif word=="女子":
rword="女郎"
else:
rword=word
counts[word] = counts.get(word,0) + 1
for word in excludes:
del(counts[word])
items = list(counts.items())
items.sort(key=lambda x:x[1], reverse=True)
for i in range(20):
word, count = items[i]
print ("{0:<10}{1:>5}".format(word, count))ss

 

posted @ 2023-12-17 22:18  还是一个人a  阅读(25)  评论(0)    收藏  举报