Re: display of dicts?

Chris Barker <[email protected]> Mon, 18 Dec 2017 17:56:56 -0800
Newsgroups gmane.comp.python.ipython.devel
Message-ID <CALGmxELYnEfJt7rUxDKVyQoXV+2fa4v0r52PT4CVXsTT+KcdNA@mail.gmail.com>
--===============4543738130652535651==
Content-Type: multipart/alternative; boundary="94eb2c0c63848709dd0560a7ca3e"

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

Thanks Nathan,

And to confirm, this is the stdlib's pprint module, yes?

(which does seem to show the same behavior)

-CHB



On Mon, Dec 18, 2017 at 5:40 PM, Nathan Goldbaum <[email protected]>
wrote:

> 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
>>
>>
>
> _______________________________________________
> IPython-dev mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/ipython-dev
>
>


-- 

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]

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

<div dir=3D"ltr"><div><div><div>Thanks Nathan,<br><br></div>And to confirm,=
 this is the stdlib&#39;s pprint module, yes?<br><br></div>(which does seem=
 to show the same behavior)<br><br></div>-CHB<br><br><div><div><br></div></=
div></div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Mon,=
 Dec 18, 2017 at 5:40 PM, Nathan Goldbaum <span dir=3D"ltr">&lt;<a href=3D"=
mailto:[email protected]" target=3D"_blank">[email protected]</a>&g=
t;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0=
 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">IPython=
 does use pretty-printing by default. You can control it with the %pprint m=
agic, in your IPython configuration, with the PlainTextFormatter.pprint opt=
ion, or with the --pprint command line argument when starting IPython.<br><=
br><a href=3D"http://ipython.readthedocs.io/en/stable/config/options/termin=
al.html#configtrait-PlainTextFormatter.pprint" target=3D"_blank">http://ipy=
thon.readthedocs.io/<wbr>en/stable/config/options/<wbr>terminal.html#config=
trait-<wbr>PlainTextFormatter.pprint</a><br><br><br></div><div class=3D"gma=
il_extra"><br><div class=3D"gmail_quote"><div><div class=3D"h5">On Mon, Dec=
 18, 2017 at 7:08 PM, Chris Barker <span dir=3D"ltr">&lt;<a href=3D"mailto:=
[email protected]" target=3D"_blank">[email protected]</a>&gt;</spa=
n> wrote:<br></div></div><blockquote class=3D"gmail_quote" style=3D"margin:=
0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class=3D"=
h5"><div dir=3D"ltr"><div>As Guido has just declared that dicts will now of=
ficially preserve order:<br clear=3D"all"><div><br><a href=3D"https://mail.=
python.org/pipermail/python-dev/2017-December/151283.html" target=3D"_blank=
">https://mail.python.org/piperm<wbr>ail/python-dev/2017-December/<wbr>1512=
83.html</a><br><br></div><div>I was playing around=C2=A0 them in py3.6 ipyt=
hon, and found some (to me) odd behavior:<br><br><span style=3D"font-family=
:monospace,monospace">In [1]: d =3D {&#39;one&#39;:1, &#39;two&#39;:2, &#39=
;three&#39;:3}<br><br>In [2]: d<br>Out[2]: {&#39;one&#39;: 1, &#39;three&#3=
9;: 3, &#39;two&#39;: 2}<br><br></span></div>Hmm -- order does not appear t=
o be preserved.<br><br></div>But then:<span style=3D"font-family:monospace,=
monospace"></span><br><div><span style=3D"font-family:monospace,monospace">=
</span><div><span style=3D"font-family:monospace,monospace"><br>In [3]: str=
(d)<br>Out[3]: &quot;{&#39;one&#39;: 1, &#39;two&#39;: 2, &#39;three&#39;: =
3}&quot;<br><br>In [4]: repr(d)<br>Out[4]: &quot;{&#39;one&#39;: 1, &#39;tw=
o&#39;: 2, &#39;three&#39;: 3}&quot;<br><br>In [5]: d.values()<br>Out[5]: d=
ict_values([1, 2, 3])<br><br>In [6]: d.keys()<br>Out[6]: dict_keys([&#39;on=
e&#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 presuma=
bly iPython is calling sorted() or some such when displaying a dict. <br><b=
r></div><div>Is that that case? Is that documented anywhere?? I can&#39;t f=
ind it.<br><br></div><div>And with Python &gt;=3D 3.6, dict order is preser=
ved, so it would probably be better to NOT mess with dict order when displa=
ying 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 ol=
d ones on <a href=3D"http://scipy.org" target=3D"_blank">scipy.org</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 archives of those=
 stop last March)<span class=3D"m_3404512757170262343HOEnZb"><font color=3D=
"#888888"><br><br></font></span></div><span class=3D"m_3404512757170262343H=
OEnZb"><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_34045127571702623=
43m_-4512783311611731130gmail_signature"><br>Christopher Barker, Ph.D.<br>O=
ceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&amp;R =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<a href=3D"tel:(206)%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:(206)%20526-6329" value=
=3D"+12065266329" target=3D"_blank">(206) 526-6329</a>=C2=A0=C2=A0 fax<br>S=
eattle, WA =C2=A098115 =C2=A0 =C2=A0 =C2=A0=C2=A0<a href=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:[email protected]" target=
=3D"_blank">[email protected]</a></div>
</div></font></span></div></div>
<br></div></div>______________________________<wbr>_________________<br>
IPython-dev mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">IPython-dev@pyt=
hon.org</a><br>
<a href=3D"https://mail.python.org/mailman/listinfo/ipython-dev" rel=3D"nor=
eferrer" target=3D"_blank">https://mail.python.org/mailma<wbr>n/listinfo/ip=
ython-dev</a><br>
<br></blockquote></div><br></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><br clear=3D"all"><br>-- <br><div class=3D"gmail=
_signature" data-smartmail=3D"gmail_signature"><br>Christopher Barker, Ph.D=
.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&amp;R =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(206) 526-6959=C2=A0=C2=A0 voice<b=
r>7600 Sand Point Way NE =C2=A0=C2=A0(206) 526-6329=C2=A0=C2=A0 fax<br>Seat=
tle, WA =C2=A098115 =C2=A0 =C2=A0 =C2=A0=C2=A0(206) 526-6317=C2=A0=C2=A0 ma=
in reception<br><br><a href=3D"mailto:[email protected]" target=3D"_bla=
nk">[email protected]</a></div>
</div>

--94eb2c0c63848709dd0560a7ca3e--

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

--===============4543738130652535651==--