jieba分词

import jieba
import collections

with open('journey_to_the_west.txt', 'r', encoding='utf-8') as f:
    text = f.read()

words = jieba.cut(text)

word_counts = collections.Counter(words)

top_20_words = word_counts.most_common(20)

for word, count in top_20_words:
    print(word, count)

 

posted @ 2023-12-18 18:39  laidisi  阅读(16)  评论(0)    收藏  举报