标签:col com code top pen img reverse png split()
1.读入待分析的字符串
2.分解提取单词
3.计数字典
4.排除语法型词汇
5.排序
6.输出TOP(20)
fo=open(‘C:/1.txt‘,‘r‘) w=fo.read() w=w.lower() for i in ‘,.‘: w=w.replace(i,‘ ‘) words=w.split() print(words) dic={} keys=set(words) print(keys) for i in keys: dic[i]=words.count(i) print(dic) wc = list(dic.items()) wc.sort(key=lambda x:x[1],reverse=True) print(wc) print(‘TOP20:\n‘) for i in range(20): print(wc[i]) fo.close()
标签:col com code top pen img reverse png split()
原文地址:http://www.cnblogs.com/123hi/p/7598511.html