码迷,mamicode.com
首页 > 编程语言 > 详细

利用python处理文档中各字段出现的次数并排序

时间:2017-03-10 20:48:22      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:code   with   open   dex   class   path   blog   利用   python   

1 import string
2 path = waldnn
3 with open(path,r) as text:
4     words = [raw_word.strip(string.punctuation).lower() for raw_word in text.read().split()]
5     words_index = set(words)
6     counts_dict = {index:words.count(index) for index in words_index}
7 
8 for word in sorted(counts_dict,key=lambda x: counts_dict[x],reverse=True):
9     print({} -- {} times.format(word,counts_dict[word]))

 

利用python处理文档中各字段出现的次数并排序

标签:code   with   open   dex   class   path   blog   利用   python   

原文地址:http://www.cnblogs.com/Erick-L/p/6532757.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!