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))
原文地址:https://www.cnblogs.com/Mysterious/p/7479752.html