擅长:python、mysql、java
<p>使用<code>collections.Counter</code>,使用<code>sorted</code>对项目进行排序,传入自定义键函数:</p>
<pre><code>>>> from collections import Counter
>>> values = [1,5,1,1,6,3,3,4,5,5,5,2,5]
>>> counts = Counter(values)
>>> for k, count in reversed(counts.most_common()):
>>> print(k, count * 'x')
2 x
4 x
6 x
3 xx
1 xxx
5 xxxxx
</code></pre>