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))