On Thursday, July 31, 2014 2:23:03 PM UTC-7, Travis Scrimshaw wrote:
>
> I disagree with sorting the output of dicts. I ended up finding a very
> subtle bug dealing with dictionary output that I would have had a much
> harder time figuring out with the automatic sorting. Just do
> ``sorted(d.items(), key=str)`` for doctests where the order could change
> (which usually is for dicts of size larger than 3).
>
In any case we should ensure that doctesting and the command line behave
similarly, so in all cases we should probably doctest through IPytthon's
displayhook. It's just silly if one cannot paste (deterministic) output
from the command line into a doctest and get a valid doctest.
With that in mind, your point would have to be addressed by changing
IPython's displayhook to not sort dictionaries. I think there's an argument
to be made for that. If printing on the command line appears deterministic,
a user might easily be led to believe that order is really there and, for
instance, think that
for a in D:
if D[a]=="value": break
else:
raise ValueError
will find the a with "value" as suggested by the print order (which in
IPython can be wildly different from the iteration order of a dictionary).
>From that point of view, IPython's sorting is a bit of a misfeature.
However, when looking at a dict casually and inspecting whether a certain
key occurs in the printout, having the output sorted (if possible) can be
pretty convenient too. So I'm ambivalent towards retaining/turning off
IPython's sorting prettyprinter. Given that it would be quite a bit of work
to alter IPython's prettyprinter, I think that leads to accepting sorted
pretty-printed dicts for now.
--
You received this message because you are subscribed to the Google Groups
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.