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))
posted on 2017-09-05 17:31  神秘藏宝室  阅读(470)  评论(0编辑  收藏  举报

 >>>转载请注明出处<<<