擅长:python、mysql、java
<p>这是<code>collections.Counter</code>的一个很好的用例:</p>
<pre><code>from collections import Counter
scores = Counter()
with open('my_file') as f:
for line in f:
key, score = line.split()
scores.update({key: int(score)})
for key, score in scores.most_common():
print(key, score)
</code></pre>