标签:count item .com code close set 简单的 print http
中文分词
import jieba book=open(‘D:\\shui.txt‘,‘r‘,encoding=‘utf-8‘) #读入待分析的字符串 str=book.read() book.close() for i in ‘,。!、 \n “ ” ;‘: str=str.replace(i,‘‘) words=jieba.cut(str) word=set(words) #计数字典 dic={} for i in word: if len(i)>1: dic[i]=str.count(i) str=list(dic.items()) #排序 str.sort(key=lambda x:x[1],reverse=True) for i in range(20): print(str[i])
标签:count item .com code close set 简单的 print http
原文地址:http://www.cnblogs.com/yeyuanchao/p/7610631.html