练习题:统计一段英语文章的单词频率,取出频率最高的5个单词和个数(用python实现)
先全部转为小写再判定 lower()
怎么判定单词?
1 不是字母的特殊字符作为分隔符分割字符串 (避免特殊字符的处理不便,全部替换成'-')
2 正则分割
3 遍历字符串,取每个word
4 正则匹配
怎么统计个数?
将wordlist的word和word的个数放入dict,排序
''' dinghanhua 2018-11-11 练习:一段英文文章,统计每个单词的频率,返回出现频率最高的5个单词和次数 ''' import re art = ' If we want to" run Locust \ / distributed on multiple machines we would also have to specify the master host when starting the slaves (this is not needed when running