对字典排序:
推荐使用:Python SortedContainers Module
一款纯python写的对列表、字典、集合排序的模块
Sorted Containers是Apache2许可的Sorted Collections库,用纯Python编写,并且速度与C扩展一样快。在需要排序的集合类型之前,Python的标准库非常有用。许多人会证明,即使没有排序,您也可以真正走得很远,但是,当您真正需要排序列表,排序dict或排序集时,您将面临许多不同的实现,其中大多数使用C扩展而没有出色的文档和基准。在Python中,我们可以做得更好。我们可以用纯Python做到这一点!
>>> from sortedcontainers import SortedList
>>> sl = SortedList(['e', 'a', 'c', 'd', 'b'])
>>> sl
SortedList(['a', 'b', 'c', 'd', 'e'])
>>> sl *= 10_000_000
>>> sl.count('c')
10000000
>>> sl[-3:]
['e', 'e', 'e']
>>> from sortedcontainers import Sorte