import jieba
c=open(r'C:\Users\李建宏\Desktop\《聊斋志异》白话简写版.txt')
fenci=jieba.lcut(c.read())
a=[] #列表中分词
for word in fenci:
if len(word) == 1:
continue
else:
a.append(word)
continue
count=dict.fromkeys(a)
for i in count.keys():
count[i]=0
for j in a:
if j in count.keys():
count[j]+=1
item=list(count.items())
item.sort(key=lambda x:x[1],reverse=True)
for i in range(20):
word,count=item[i]
print("{0:<5}{1:>5}".format(word,count))