import re

regex = "[a-zA-Z]+"

with open("./test.py") as f:
    lines = f.readlines()

worddict = dict()
for line in lines:
    words = re.findall(regex, line)
    for word in words:
        if word in worddict.keys():
            worddict[word] += 1
        else:
            worddict[word] = 1

words_top10 = sorted(worddict.items(), key=lambda x: x[1], reverse=True)

print(words_top10) 

 

相关文章:

  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-26
  • 2021-09-06
猜你喜欢
  • 2021-11-29
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案