Relevant to recent discussion on sage-devel...

Forwarded conversation
Subject: [IPython-dev] display of dicts?
------------------------

From: Chris Barker <[email protected]>
Date: Mon, Dec 18, 2017 at 5:08 PM
To: [email protected]


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


----------
From: Nathan Goldbaum <[email protected]>
Date: Mon, Dec 18, 2017 at 5:40 PM
To: IPython Community list <[email protected]>


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



_______________________________________________
> 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





-- 
William (http://wstein.org)

-- 
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 https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to