import jiebafr = open(‘tridebody.txt‘,‘r‘,encoding = ‘utf-8‘)str = fr.read()fr.close()words = jieba.cut(str)words = list(words)print(‘{0:-^50)‘.format(‘分词解析成功!‘))di = 0;dise = set(words)print(‘分词统计中------‘)for i in dise: print(i) di[i] =words.count(i)wc = list(di.items())#print(wc)wc.sort(key= lambda x:x[i],reverse = True)#print(wc)print(‘{0:-^50}‘.format(‘词频统计结果前10‘))for i in range(len(dise)): print(‘{0} = {1}‘.format(wc[i][0].wc[i][1]))
时间: 2024-10-31 06:31:09