[Python-Dev] Guarantee ordered dict literals in v3.7?

Chris Barker chris.barker at noaa.gov
Mon Dec 18 23:28:52 EST 2017


On Mon, Dec 18, 2017 at 7:41 PM, Steven D'Aprano <steve at pearwood.info>
wrote:

> > With arbitrary order, it made sense to sort, so as to always give the
> same
> > "pretty" representation. But now that order is "part of" the dict itself,
> > it seems prettyprint should present the preserved order of the dict.
>
> I disagree. Many uses of dicts are still conceptually unordered, even if
> the dict now preserves insertion order. For those use-cases, insertion
> order is of no interest whatsoever, and sorting is still "prettier".
>

and many uses of dicts have "sorted" order as completely irrelevant, and
sorting them arbitrarily is not necessarily pretty (you can't provide a
sort key can you? -- so yes, it's arbitrary)

I'm not necessarily saying we should break things, but I won't agree that
pprint sorting dicts is the "right" interface for what is actually an
order-preserving mapping.

I would think it was only the right choice in the first place in order (get
it?) to get a consistent representation, not because sorting was a good
thing per se.

-Chris

-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171218/9483d0ae/attachment.html>


More information about the Python-Dev mailing list