Why are there no sorted containers in Python's standard libraries?

后端 未结 6 1017
执念已碎
执念已碎 2020-12-02 18:06

Is there a Python design decision (PEP) that precludes a sorted container from being added to Python?

(OrderedDict is not a sorted container since it is

6条回答
  •  被撕碎了的回忆
    2020-12-02 18:29

    Python lists are ordered. If you sort them, they stay that way. In Python 2.7 an OrderedDict type was added to maintain an explicitly ordereded dictionary.

    Python also has sets (a collection in which the members must be unique), but by definition they are unordered. Sorting a set just returns a list.

提交回复
热议问题