On Tue, Dec 19, 2017 at 4:49 PM, Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote:
> Nathaniel Smith writes: > > > To make sure I understand, do you actually have a script like this, or > > is this hypothetical? > > I have a couple of doctests that assume that pprint will sort by key, > yes. It makes the tests look quite a bit nicer by pprinting the > output, and I get sorting (which matters for some older Pythons) for > free. (I admit I don't actually use those tests with older Pythons, > but the principle stands.) > > I don't see why we don't do the obvious, namely add the option to use > "native" order to the PrettyPrinter class, with the default being > backward compatible. > Perhaps now key ordering has been pronounced we could either add a "sorted" method to dicts equivalent to the following code. def sorted(self): return {self[k] for k in sorted(self.keys())} 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. regards Steve
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com