import jiebaf=open('sanwen.txt','r')text=f.read()wordlist=list(jieba.lcut(text))Words={}for i in set(wordlist): Words[i]=wordlist.count(i)delete_word={ '中国的', '是',',','。',':','“','”','的','啊','在','了', '去','与','不','、','也','又','就', '和'}for i in delete_word: if i in Words: del Words[i]sort_word = sorted(Words.items(), key= lambda d:d[1], reverse = True)for i in range(10): print(sort_word[i])
运行截图: