Re: display of dicts?

Nathan Goldbaum <[email protected]> Mon, 18 Dec 2017 19:40:02 -0600
Newsgroups gmane.comp.python.ipython.devel
Message-ID <CAJXewOk64cQ3MvSX6yTGDQT2W-gXybbUfLOa5vD4wfqH3tRGeQ@mail.gmail.com>
--===============0851958746044257886==
Content-Type: multipart/alternative; boundary="f40304388ad8e8f72c0560a78caa"

--f40304388ad8e8f72c0560a78caa
Content-Type: text/plain; charset="UTF-8"

IPython does use pretty-printing by default. You can control it with the
%pprint magic, in your IPython configuration, with the
PlainTextFormatter.pprint option, or with the --pprint command line
argument when starting IPython.

http://ipython.readthedocs.io/en/stable/config/options/terminal.html#configtrait-PlainTextFormatter.pprint



On Mon, Dec 18, 2017 at 7:08 PM, Chris Barker <[email protected]> wrote:

> As Guido has just declared that dicts will now officially preserve order:
>
> https://mail.python.org/pipermail/python-dev/2017-December/151283.html
>
> I was playing around  them in py3.6 ipython, and found some (to me) odd
> behavior:
>
> In [1]: d = {'one':1, 'two':2, 'three':3}
>
> In [2]: d
> Out[2]: {'one': 1, 'three': 3, 'two': 2}
>
> Hmm -- order does not appear to be preserved.
>
> But then:
>
> In [3]: str(d)
> Out[3]: "{'one': 1, 'two': 2, 'three': 3}"
>
> In [4]: repr(d)
> Out[4]: "{'one': 1, 'two': 2, 'three': 3}"
>
> In [5]: d.values()
> Out[5]: dict_values([1, 2, 3])
>
> In [6]: d.keys()
> Out[6]: dict_keys(['one', 'two', 'three'])
>
> In [7]: d.items()
> Out[7]: dict_items([('one', 1), ('two', 2), ('three', 3)])
>
> Order IS preserved.
>
> So presumably iPython is calling sorted() or some such when displaying a
> dict.
>
> Is that that case? Is that documented anywhere?? I can't find it.
>
> And with Python >= 3.6, dict order is preserved, so it would probably be
> better to NOT mess with dict order when displaying them in iPython.
>
> SIDE NOTE:
>
> I had a bit of trouble finding this mailing list -- google still points to
> the old ones on scipy.org. -- maybe we can put a note on the home page of
> those lists that they are been moved??
>
> (I only noticed, 'cause the archives of those stop last March)
>
> -Chris
>
>
>
>
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R            (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> [email protected]
>
> _______________________________________________
> IPython-dev mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/ipython-dev
>
>

--f40304388ad8e8f72c0560a78caa
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">IPython does use pretty-printing by default. You can contr=
ol it with the %pprint magic, in your IPython configuration, with the Plain=
TextFormatter.pprint option, or with the --pprint command line argument whe=
n starting IPython.<br><br><a href=3D"http://ipython.readthedocs.io/en/stab=
le/config/options/terminal.html#configtrait-PlainTextFormatter.pprint">http=
://ipython.readthedocs.io/en/stable/config/options/terminal.html#configtrai=
t-PlainTextFormatter.pprint</a><br><br><br></div><div class=3D"gmail_extra"=
><br><div class=3D"gmail_quote">On Mon, Dec 18, 2017 at 7:08 PM, Chris Bark=
er <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D=
"_blank">[email protected]</a>&gt;</span> wrote:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex"><div dir=3D"ltr"><div>As Guido has just declared that dicts w=
ill now officially preserve order:<br clear=3D"all"><div><br><a href=3D"htt=
ps://mail.python.org/pipermail/python-dev/2017-December/151283.html" target=
=3D"_blank">https://mail.python.org/<wbr>pipermail/python-dev/2017-<wbr>Dec=
ember/151283.html</a><br><br></div><div>I was playing around=C2=A0 them in =
py3.6 ipython, and found some (to me) odd behavior:<br><br><span style=3D"f=
ont-family:monospace,monospace">In [1]: d =3D {&#39;one&#39;:1, &#39;two&#3=
9;:2, &#39;three&#39;:3}<br><br>In [2]: d<br>Out[2]: {&#39;one&#39;: 1, &#3=
9;three&#39;: 3, &#39;two&#39;: 2}<br><br></span></div>Hmm -- order does no=
t appear to be preserved.<br><br></div>But then:<span style=3D"font-family:=
monospace,monospace"></span><br><div><span style=3D"font-family:monospace,m=
onospace"></span><div><span style=3D"font-family:monospace,monospace"><br>I=
n [3]: str(d)<br>Out[3]: &quot;{&#39;one&#39;: 1, &#39;two&#39;: 2, &#39;th=
ree&#39;: 3}&quot;<br><br>In [4]: repr(d)<br>Out[4]: &quot;{&#39;one&#39;: =
1, &#39;two&#39;: 2, &#39;three&#39;: 3}&quot;<br><br>In [5]: d.values()<br=
>Out[5]: dict_values([1, 2, 3])<br><br>In [6]: d.keys()<br>Out[6]: dict_key=
s([&#39;one&#39;, &#39;two&#39;, &#39;three&#39;])<br><br>In [7]: d.items()=
<br>Out[7]: dict_items([(&#39;one&#39;, 1), (&#39;two&#39;, 2), (&#39;three=
&#39;, 3)])<br></span><br></div><div>Order IS preserved.<br><br></div><div>=
So presumably iPython is calling sorted() or some such when displaying a di=
ct. <br><br></div><div>Is that that case? Is that documented anywhere?? I c=
an&#39;t find it.<br><br></div><div>And with Python &gt;=3D 3.6, dict order=
 is preserved, so it would probably be better to NOT mess with dict order w=
hen displaying them in iPython.<br><br></div><div>SIDE NOTE:<br></div><div>=
<br>I had a bit of trouble finding this mailing list -- google still points=
 to the old ones on <a href=3D"http://scipy.org" target=3D"_blank">scipy.or=
g</a>. -- maybe we can put a note on the home page of those lists that they=
 are been moved??<br><br></div><div>(I only noticed, &#39;cause the archive=
s of those stop last March)<span class=3D"HOEnZb"><font color=3D"#888888"><=
br><br></font></span></div><span class=3D"HOEnZb"><font color=3D"#888888"><=
div>-Chris<br></div><div><br></div><div><br></div><div><br><br></div><div><=
br>-- <br><div class=3D"m_-4512783311611731130gmail_signature"><br>Christop=
her Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NO=
AA/NOS/OR&amp;R =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<a href=3D"tel:(20=
6)%20526-6959" value=3D"+12065266959" target=3D"_blank">(206) 526-6959</a>=
=C2=A0=C2=A0 voice<br>7600 Sand Point Way NE =C2=A0=C2=A0<a href=3D"tel:(20=
6)%20526-6329" value=3D"+12065266329" target=3D"_blank">(206) 526-6329</a>=
=C2=A0=C2=A0 fax<br>Seattle, WA =C2=A098115 =C2=A0 =C2=A0 =C2=A0=C2=A0<a hr=
ef=3D"tel:(206)%20526-6317" value=3D"+12065266317" target=3D"_blank">(206) =
526-6317</a>=C2=A0=C2=A0 main reception<br><br><a href=3D"mailto:Chris.Bark=
[email protected]" target=3D"_blank">[email protected]</a></div>
</div></font></span></div></div>
<br>______________________________<wbr>_________________<br>
IPython-dev mailing list<br>
<a href=3D"mailto:[email protected]">[email protected]</a><br>
<a href=3D"https://mail.python.org/mailman/listinfo/ipython-dev" rel=3D"nor=
eferrer" target=3D"_blank">https://mail.python.org/<wbr>mailman/listinfo/ip=
ython-dev</a><br>
<br></blockquote></div><br></div>

--f40304388ad8e8f72c0560a78caa--

--===============0851958746044257886==
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

--===============0851958746044257886==--