标签:nts for top code es2017 imp cut reverse count
1.中软国际华南区技术总监曾老师还会来上两次课,同学们希望曾老师讲些什么内容?(认真想一想回答)
希望老师详细讲一下python在网络编程的应用
2.中文分词
A.使用jieba库,进行中文词频统计,输出TOP20的词及出现次数。
import jieba txt = open("C:/Users/Administrator/Desktop/4-昆仑神宫.txt","r",encoding=‘utf-8‘).read() words = jieba.cut(txt) counts = {} for w in words: if len(w) == 1: continue else: counts[w] = counts.get(w,0) + 1 items = list(counts.items()) items.sort(key=lambda x:x[1],reverse=True) for i in range(20): w,count = items[i] print("{0:<10}{1:>5}".format(w,count))
标签:nts for top code es2017 imp cut reverse count
原文地址:http://www.cnblogs.com/gzw2017/p/7592867.html