<div dir="ltr"><div class="gmail_default" style="font-size:small">On Tue, Dec 19, 2017 at 4:49 PM, Stephen J. Turnbull <span dir="ltr"><<a href="mailto:turnbull.stephen.fw@u.tsukuba.ac.jp" target="_blank">turnbull.stephen.fw@u.tsukuba.ac.jp</a>></span> wrote:<br></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Nathaniel Smith writes:<br>
<br>
 > To make sure I understand, do you actually have a script like this, or<br>
 > is this hypothetical?<br>
<br>
</span>I have a couple of doctests that assume that pprint will sort by key,<br>
yes.  It makes the tests look quite a bit nicer by pprinting the<br>
output, and I get sorting (which matters for some older Pythons) for<br>
free.  (I admit I don't actually use those tests with older Pythons,<br>
but the principle stands.)<br>
<br>
I don't see why we don't do the obvious, namely add the option to use<br>
"native" order to the PrettyPrinter class, with the default being<br>
backward compatible.<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">​Perhaps now key ordering has been pronounced we could either add a "sorted" method to dicts equivalent to the following code.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">        def sorted(self):​</div><div class="gmail_default" style="font-size:small">            return {self[k] for k in sorted(self.keys())}</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Alternatively the sorted built-in could be modified to handle dicts in this way. Though I still find the assumption of any ordering at all a bit weird I suppose I'll grow used to it.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">regards</div><div class="gmail_default" style="font-size:small"> Steve</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><br></div></div></div></div>