用正则表达式清除各类符号
一篇文章,先转为单词为元素的列表。 分解时遇到的第一个问题,就是如果去除各类标点符号。 import re 运算结果,['asdf','fjdk','afred','fjek','asdf','foo','sdkk'] 在得到分解LIST后,就可以进行单词分析了。要用到Counter工具。 words = [ 'look','into','my','eyes','look', 'the','the','not','around',255);"> 'eyes',"don't",255);"> 'my',"you're",'under' ] from collections import Counter word_counts = Counter(words) top_three = word_counts.most_common(3) print(top_three) # Outputs [('eyes',8),('the',5),('look',4)] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |