[Python-Dev] Guarantee ordered dict literals in v3.7?
encukou at gmail.com
Tue Nov 7 04:51:46 EST 2017
On 11/07/2017 09:00 AM, Wolfgang wrote:
> Also it is fine to teach people that dict (Mapping) is not ordered
> but CPython has an implementation detail and it is ordered.
> But if you want the guarantee use OrderedDict.
I don't think that is fine.
When I explained this in 3.5, dicts rearranging themselves seemed quite
weird to the newcomers.
This year, I'm not looking forward to saying that dicts behave
"intuitively", but you shouldn't rely on that, because they're
theoretically allowed to rearrange themselves.
The concept of "implementation detail" and language spec vs. multiple
interpreter implementations isn't easy to explain to someone in a "basic
coding literacy" course.
Today I can still show an example on Python 3.5. But most people I teach
today won't run their code on 3.5, or on MicroPython or Brython, and
quite soon they'll forget that there's no dict ordering guarantee.
Also: I happen to read python-dev and the language docs. I suspect not
all teachers do, and when they see that dict order randomization was
"fixed", they might just remove the explanation from the lesson and
teach something practical instead.
More information about the Python-Dev