擅长:python、mysql、java
<p>另一种使用容器数据类型<em>计数器</em><a href="https://docs.python.org/3/library/collections.html" rel="nofollow noreferrer">https://docs.python.org/3/library/collections.html</a></p>
<pre><code>import urllib.request
from collections import Counter
with urllib.request.urlopen('http://data.pr4e.org/romeo.txt') as response:
words = response.read().decode('utf-8').split()
c = Counter(words)
# optionally
print(c.most_common())
</code></pre>