南城游子的博客本文实例讲述了python统计文本文件内单词数量的方法。分享给大家供大家参考。具体实现方法如下:# count lines, sentences, and words of a text file# set all the counters to zerolines, blanklines, sentences, ...
weixin_39766014的博客1.读文件,通过正则匹配def statisticWord():line_number = 0words_dict = {}with open (r'D:\test\test.txt',encoding='utf-8') as a_file:for line in a_file:words = re.findall(r'&#\d+;|&#\d+;|&\w+;',line...