1,把要统计的文字保存在hamlet.txt中,并和Python程序放在同一目录中
2,以下是Python代码:
import re
from collections import Counter
words = re.findall(r'\w+', open('hamlet.txt').read().lower())
print(Counter(words).most_common(10))
1,把要统计的文字保存在hamlet.txt中,并和Python程序放在同一目录中
2,以下是Python代码:
import re
from collections import Counter
words = re.findall(r'\w+', open('hamlet.txt').read().lower())
print(Counter(words).most_common(10))