[IPython-dev] display of dicts?

Thomas Kluyver takowl at gmail.com
Tue Dec 19 10:45:59 EST 2017


On 19 December 2017 at 15:37, Chris Barker - NOAA Federal <
chris.barker at noaa.gov> wrote:

> > On Dec 19, 2017, at 3:23 AM, Thomas Kluyver <takowl at gmail.com> wrote:
> >
> > I think this is a tricky one, as the discussion on Python-dev is finding.
>
> Indeed. But I think with iPython, at least it’s less likely that
> people are using the pretty printed results in a meaningful way.
>

I think there's less danger of us breaking someone's *code* that relies on
dictionary presentation. But it's more important for us to think about
what's useful for human interpretation, since IPython is all about the
interface.


> > But for a lot of real-world use cases, insertion order is not
> meaningful, and displaying a sorted dictionary is still going to be more
> useful.
>
> Maybe — but for many dicts, the default sort order isn’t any better
> than arbitrary anyway. In my mind, the reason to have sorted dicts for
> pretty print in the first place was to get consistency— not sorting
> per se. And we now get that out of the box.
>

I disagree with that. Consistency is part of it, but I think the sorting is
often helpful in itself. It's much easier to see if the dictionary has a
key 'foo' if it's shown in alphabetical order than if it's not.

The new dict also only gives you consistency if the data going into it is
consistently ordered. If you are building a dictionary of filenames with
os.listdir(), for example, order is not guaranteed.

Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20171219/b906ab9a/attachment-0001.html>


More information about the IPython-dev mailing list