英文文本:hamlet,统计出现最多的英文单词
代码实现:
#Hamlet词频统计
def getText():
txt = open("hamlet",'r').read()
txt = txt.lower() #大写字母转换小写
for word in '~!@#$%^&*()_+-={}[],./:";<>?':
txt = txt.replace(word," ")#把多余符号转换为空格
return txt
hamletTxt = getText()
words = hamletTxt.split() #以空格拆分为列表
counts = {
}
for word in words