import jieba fo=open('xiyouji.txt','r',encoding='utf-8') str=fo.read() fo.close() words=list(jieba.cut(str)) dt={} for i in words: if len(i)==1: continue else: dt[i]=dt.get(i,0)+1 item=list(dt.items()) item.sort(key=lambda x:x[1],reverse=True) for i in range(20): print(item[i])
运行结果: