abarnert at yahoo.com
Wed Sep 25 05:27:36 CEST 2013
From: "random832 at fastmail.us" <random832 at fastmail.us>
Sent: Tuesday, September 24, 2013 10:24 AM
> On Tue, Sep 24, 2013, at 12:33, Ram Rachum wrote:
>> For the record, I think that having a SortedDict in the stdlib would be
> There are two issues with that.
This discussion comes up at least once every two months, and I don't think anyone wants to have the whole discussion all over again. See http://stupidpythonideas.blogspot.com/2013/07/sorted-collections-in-stdlib.html, which I wrote one or two iterations ago to collect all of the issues, and please let me know if I missed any or you have anything to add.
Your two issues aren't really problems, just choices to be made, and I think everyone who's interested in this who has an opinion is unanimous. (There _is_ a problem, however: there are multiple good implementations out there, but none of them comes with someone who's willing to stdlibify it and maintain it for a few years…) But briefly:
Yes, every key must be comparable with every other key, and the comparison must define a strict weak order, and the keys must be comparison-immutable, and there's no way to test either of those automatically. By comparison, a dict needs hashable keys, which can be tested automatically, and equality-immutable and hash-immutable keys, which can't really be tested but in practice hash is an acceptable test. But it's no worse than many other requirements in the stdlib that can't be tested automatically.
And yes, NaN is a problem, but it's exactly the same problem it is everywhere else in Python.
More information about the Python-ideas