4.排除语法型词汇
exp={'','to','have','a'} keys=set(words)-exp#出现过单词的集合,字典的key.
5.排序
for i in keys: d[i]=words.count(i) #print(d) wc=list(d.items()) wc.sort(key=lambda x:x[1],reverse=True)#排序 print(wc)
6.输出TOP(20)
for i in range(20): print(wc[i])
4.排除语法型词汇
exp={'','to','have','a'} keys=set(words)-exp#出现过单词的集合,字典的key.
5.排序
for i in keys: d[i]=words.count(i) #print(d) wc=list(d.items()) wc.sort(key=lambda x:x[1],reverse=True)#排序 print(wc)
6.输出TOP(20)
for i in range(20): print(wc[i])
转载于:https://www.cnblogs.com/018linbin/p/7598990.html