第九次作业

 

 

import jieba
txt=open('test.txt','r',encoding='utf-8').read()
words=list(jieba.cut(txt))
exc={'我们','可是','自己','他们','一个',}
keys=set(words)
keys=keys-exc
dic={}#定义一个空字典
for i in keys:
    if len(i)==1:
        continue
    else:
        dic[i]=words.count(i)
        
wc=list(dic.items())
wc.sort(key=lambda x:x[1],reverse=True)#排序
for i in range(20):
    print(wc[i])

 

posted @ 2017-09-29 19:12  037吴宜珊  阅读(75)  评论(0)    收藏  举报