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

 import string
path = 'waldnn'
with open(path,'r') as text:
words = [raw_word.strip(string.punctuation).lower() for raw_word in text.read().split()]
words_index = set(words)
counts_dict = {index:words.count(index) for index in words_index} for word in sorted(counts_dict,key=lambda x: counts_dict[x],reverse=True):
print('{} -- {} times'.format(word,counts_dict[word]))
上一篇:爬虫之PyQuery的base了解


下一篇:php过滤textarea 中的换行符问题