python 统计单词出现次数
#use python3.6
import re
from collections import Counter
FILESOURCE = './abc.txt'
def getMostCommonWord(artlclefilesource):
pattern = r"""[A-Za-z]+|\$?\d+%?$"""
with open(artlclefilesource) as f:
r = re.findall(pattern,f.read())
return Counter(r).most_common()
if __name__ == "__main__":
print(getMostCommonWord(FILESOURCE))
文章对您有帮助,开心可以打赏我,金额随意,欢迎来赏!
需要电子方面开发板/传感器/模块等硬件可以到我的淘宝店逛逛