请你回答一下:统计文本中出现次数前十的单词,文件很大,不能一次性读入内存?
import re from collections import Counter with open('1.txt', 'r', ) as f: words = f.read() # 将文件的内容全部读取成一个字符串 count = Counter(re.split(r"\W+", words)) # 以单词为分隔 result = count.most_common(10) # 统计最常使用的前10个 print(result)