是否存在阻止将已排序容器添加到 Python 的 Python 设计决策 (PEP)?
(OrderedDict
不是排序容器,因为它是按插入顺序排序的。)
最佳答案
还有一条 python sortedcontainers实现排序列表、字典和集合类型的模块。它与 blist 非常相似,但在 pure-Python 中实现,在大多数情况下 faster .
>>> from sortedcontainers import SortedSet
>>> ss = SortedSet([3, 7, 2, 2])
>>> ss
SortedSet([2, 3, 7])
它还具有其他软件包不常见的功能:
>>> from sortedcontainers import SortedDict
>>> sd = SortedDict((num, num) for num in range(100000))
>>> sd.iloc[-5] # Lookup the fifth-to-last key.
99995
披露:我是 sortedcontainers 模块的作者。
关于python - 为什么 Python 的标准库中没有排序容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5953205/