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]))

 

相关文章:

猜你喜欢
  • 2022-03-07
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2021-12-28
  • 2022-12-23
  • 2021-07-18
相关资源
相似解决方案