[Python-Dev] Guarantee ordered dict literals in v3.7? (original) (raw)
Chris Barker chris.barker at noaa.gov
Tue Nov 7 16:13:32 EST 2017
- Previous message (by thread): [Python-Dev] Guarantee ordered dict literals in v3.7?
- Next message (by thread): [Python-Dev] Guarantee ordered dict literals in v3.7?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Nov 7, 2017 at 7:21 AM, David Mertz <mertz at gnosis.cx> wrote:
But like Raymond, I make most of my living TEACHING Python.
and I make least of my living TEACHING Python ( :-) ),and:
I feel like the extra order guarantee would make teaching slightly harder.
I can't understand how this possibly makes python (or dicts) harder to teach -- you can simply say: "dicts insertion order is preserved" or not mention it at all -- I think most people kind of expect it to be preserved, which is why I (used to )always bring up the lack-of-ordering of dicts early on -- but I suspect I simply won't bother mentioning it if it's decided as a language feature.
I'm sure he feels contrarily. It is true that with 3.6 I can no longer show
an example where the dict display is oddly changed when printed.
Exactly! I have a really hard time deciding how to handle this -- explaining that ordering is not guaranteed, but not being able to demonstrate it! And frankly, my students are all going to forget what I "explained" soon enough, and replace it with their experience -- which will be that dicts retain their order.
But then, unordered sets also wind up sorting small integers on printing,
even though that's not a guarantee.
but it's not hard to make an easy example with order not preserved -- jsut start with a non order example:
In [6]: s = {3,7,4}
In [7]: s
Out[7]: {3, 4, 7}
or use other types...
And "set" is a mathematical concept that has no oder, whereas the "dictionary" metaphor DOES have order...
Ordering by insertion order (possibly "only until first deletion") is simply not obvious to beginners.
the "only until first deletion" part is really hard -- I hope we don't go that route. But I don't think insertion-order is non-obvious -- particularly with literals.
If we had, hypothetically, a dict that "always alphabetized keys" that would be more intuitive to them, for example. Insertion order feels obvious to us experts, but it really is an extra cognitive burden to learners beyond understanding "key/Val association".
again, I don't think so -- I kind of agree if dicts did not preserve order in practice -- demonstrating that right out of the gate does help make the "key/Val association" clear -- but if you can't demonstrate it, I think we're looking at more confusion...
Maybe I'll ask my students this evening -- this is the first class I'm teaching with py3.6 ....
We've lived without order for so long that it seems that some of us now
think data scrambling is a virtue. But it isn't. Scrambled data is the opposite of human friendly.
exactly!
-CHB
--
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
Chris.Barker at noaa.gov -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20171107/d4bff0d5/attachment.html>
- Previous message (by thread): [Python-Dev] Guarantee ordered dict literals in v3.7?
- Next message (by thread): [Python-Dev] Guarantee ordered dict literals in v3.7?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]