一行至三行命令能做的事
作者:互联网
找到在 Hamlet.txt 中出现最多的10个词
>>> import re
>>> words = re.findall(r'\w+', open('hamlet.txt').read().lower())
>>> Counter(words).most_common(10)
[('the', 1143), ('and', 966), ('to', 762), ('of', 669), ('i', 631),
('you', 554), ('a', 546), ('my', 514), ('hamlet', 471), ('in', 451)]
参考:
https://docs.python.org/2/library/collections.html
标签:10,1143,re,hamlet,命令,三行,words,txt,行至 来源: https://blog.csdn.net/m0_37586991/article/details/89739525