标签: python counter
我的文件大小为16.5GB,我按照以下代码计算单词:
import re from collections import Counter c = Counter() with open('log.txt') as f: for line in f: c.update(re.findall(r'\w+',line)) for w, t in c.most_common(): print w, t
有没有办法更快地计算它?