Re: display of dicts?
Thomas Kluyver <[email protected]> Tue, 19 Dec 2017 15:45:59 +0000
| Newsgroups | gmane.comp.python.ipython.devel |
|---|---|
| Message-ID | <CAOvn4qjT9S750YfAKi_mDAxFkYei_-c+-JZLC8Vk57a50RESng@mail.gmail.com> |
--===============3971171810261928486== Content-Type: multipart/alternative; boundary="94eb2c073436da5c000560b35e86" --94eb2c073436da5c000560b35e86 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On 19 December 2017 at 15:37, Chris Barker - NOAA Federal < [email protected]> wrote: > > On Dec 19, 2017, at 3:23 AM, Thomas Kluyver <[email protected]> wrote: > > > > I think this is a tricky one, as the discussion on Python-dev is findin= g. > > Indeed. But I think with iPython, at least it=E2=80=99s 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 =E2=80=94 but for many dicts, the default sort order isn=E2=80=99t = 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=E2=80=94 not sorti= ng > 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 --94eb2c073436da5c000560b35e86 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 1= 9 December 2017 at 15:37, Chris Barker - NOAA Federal <span dir=3D"ltr"><= ;<a href=3D"mailto:[email protected]" target=3D"_blank">chris.barker@no= aa.gov</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"= margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class= =3D"">> On Dec 19, 2017, at 3:23 AM, Thomas Kluyver <<a href=3D"mailt= o:[email protected]">[email protected]</a>> wrote:<br> ><br> > I think this is a tricky one, as the discussion on Python-dev is findi= ng.<br> <br> </span>Indeed. But I think with iPython, at least it=E2=80=99s less likely = that<br> people are using the pretty printed results in a meaningful way.<br></block= quote><div><br></div><div>I think there's less danger of us breaking so= meone's *code* that relies on dictionary presentation. But it's mor= e important for us to think about what's useful for human interpretatio= n, since IPython is all about the interface.<br></div><div>=C2=A0</div><blo= ckquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #c= cc solid;padding-left:1ex"> <span class=3D""> > But for a lot of real-world use cases, insertion order is not meaningf= ul, and displaying a sorted dictionary is still going to be more useful.<br= > <br> </span>Maybe =E2=80=94 but for many dicts, the default sort order isn=E2=80= =99t any better<br> than arbitrary anyway. In my mind, the reason to have sorted dicts for<br> pretty print in the first place was to get consistency=E2=80=94 not sorting= <br> per se. And we now get that out of the box.<br></blockquote><div><br></div>= 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.</div><div class=3D"gmail_quote"><br></div><div class=3D"gmail_quote= ">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 o= s.listdir(), for example, order is not guaranteed.</div><div class=3D"gmail= _quote"><br></div><div class=3D"gmail_quote">Thomas<br></div></div></div> --94eb2c073436da5c000560b35e86-- --===============3971171810261928486== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ IPython-dev mailing list [email protected] https://mail.python.org/mailman/listinfo/ipython-dev --===============3971171810261928486==--