No explicit mention that dicts are ordered, and preserve insertion order

To my surprise, this week I wanted to point someone to the fact dictionaries are ordered in Python - and I remember quite clearly when it was “declared so” for Python 3.7 - but this information is not in a formal place in the documents.

In the Data Structures page, when describing about dictionaries, one can see indirect confirmation of dict ordering in the popitem() method and thatr dicts work with reversed from Python 3.8 on.

I then tried looking for a PEP which would follow the new dictionary implementation which yielded ordering “for free” - and that is also not in any PEP.WHat one can find around is the email from Guido, then the BDLF, declaring that “dicts are now ordered”. :slight_smile:

Maybe this should just go in as a documentation bug which could be fixed soonish?
And possibly it could even deserve a “posthumous” PEP, gathering the materials which led to the current behavior?

(I apologise for not enriching this post with links, due to time issues) -

1 Like

There has been an official announcement: [Python-Dev] Guarantee ordered dict literals in v3.7? and in the What’s New of 3.7: What’s New In Python 3.7 — Python 3.7.17 documentation.

I haven’t looked more in the docs themselves though but if Built-in Types — Python 3.13.2 documentation doesn’t mention insertion being kept, we could add it.

1 Like

Ok, actually it’s mentioned:

Dictionaries preserve insertion order. Note that updating a key does not affect the order. Keys added after deletion are inserted at the end.

But it’s mentioned at the end of the docs.

1 Like

From the URL above:

 Dictionaries preserve insertion order. Note that updating a key does 
 not affect the order. Keys added after deletion are inserted at the 
 end.

Cheers,
Cameron Simpson cs@cskk.id.au

2 Likes

Yes, it is indeed there - thank you and sorry for the noise.

(I can perceive how I missed the phrase in the Data Structure docs - but I am still wondered how I missed it in the “what is new” for 3.7, as I had scanned that. Maybe I’ve searched for “dicts” instead of “dict”)