斗破苍穹文本分词

import jieba
a = open(r"C:\Users\12943\Desktop\斗破苍穹.txt","r").read()
words = jieba.lcut(a)
shuliang = {}
for word in words:
    if len(word) == 1:
        continue
    else:
        shuliang[word] = shuliang.get(word,0)+1
items = list(shuliang.items())
items.sort(key=lambda x:x[1],reverse=True)
for i in range(10):
    word,count = items[i]
    print("{0:<10}{1:>5}".format(word,count))

猜你喜欢

转载自www.cnblogs.com/qq1294/p/12635503.html