擅长:python、mysql、java
<p>使用<a href="http://docs.python.org/library/collections.html#module-collections" rel="noreferrer">collections.Counter()</a>。它正是为这个用例而设计的:</p>
<pre><code>>>> import collections
>>> seq = ["House", "Dream", "Tree", "Tree", "House", "Sky", "House"]
>>> for word, cnt in collections.Counter(seq).most_common():
print repr(word), '-', cnt
'House' - 3
'Tree' - 2
'Sky' - 1
'Dream' - 1
</code></pre>