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
标签:jieba,rword,word,items,聊斋,counts,txt,分词 From: https://www.cnblogs.com/haishiyigeren/p/17909969.html