按降序排列列表中的项目数

use*_*851 2 python list

嗨,我有一个这样的列表: llist=['a','b','c','b','e','a','f','e','f','e','e','e','a'] 我使用集合中的计数器并使用:

from collections import Counter

c=Counter(llist)

print c.items()
Run Code Online (Sandbox Code Playgroud)

它打印 [('a', 3), ('c', 1), ('b', 2), ('e', 5), ('f', 2)]

我想按降序打印它们,例如

   5 e
   3 a
   2 b
   2 f
   1 c
Run Code Online (Sandbox Code Playgroud)

小智 5

这有效:

>>> from collections import Counter
>>> llist = ['a','b','c','b','e','a','f','e','f','e','e','e','a']
>>> c = Counter(llist)
>>> for i,j in c.most_common():
...     print j,i
...
5 e
3 a
2 b
2 f
1 c
>>>
Run Code Online (Sandbox Code Playgroud)

这是关于 的参考collections.Counter.most_common