Adding sortedcontainers package into the standard library?

Hi, from what I can see Python is one of the few major languages that lacks a collection of sorted containers in the standard library, I am just wondering if there are any obstacles that I am not seeing to get this very nice package into the standard library:

Please let me know your thoughts!

Adding something to the stdlib inevitably leads to the question of why it needs to be in the stdlib instead of just on PyPI? Is this something that’s widely needed by most people, or does it require coordination at the interface/protocol level?

In this instance I would argue the need isn’t wide enough to warrant pulling it into the stdlib.


Although, many people coming from other languages just assume a container such as dict is key-sorted, and not insertion-sorted. That leads to a bunch of subtle bugs which we could avoid if a sorted container module had more visibility in python, via being a part of stdlib for instance.

I’m not sure if that level of generalization can be made. For instance, I assume there’s no sorting on maps in other languages since that’s how they are typically designed. Plus you’re assuming people who make that sort of assumption will know to look in the stdlib instead of just then want it for dicts themselves.


If you “come from another language” the learning Python includes learning its differences. If you think something can be improved, then that’s worth discussion, but mere difference is good to note, but no reason for change.

One interesting case to consider: interviewing for jobs. In such cases it’s often not allowed to use a third-party library in a solution to a coding interview question, but using a language’s standard library is fair game. And often candidates are allowed to use whatever language they’re most comfortable with from among several options. The Python language sponsors at a polyglot company I know of were actually concerned about this exact problem quite recently, since one of the company’s standard interview questions gives candidates using e.g. Java an advantage over candidates using Python, since Java has sorted containers built in (which are needed for the correct solution) whereas Python does not.

1 Like