Skip to content

Dict is now ordered. Maybe the book should be updated? #95

Open
@gbnewb

Description

@gbnewb

As of Python 3.6, for the CPython implementation of Python, dictionaries remember the order of items inserted. This is considered an implementation detail in Python 3.6; you need to use OrderedDict if you want insertion ordering that's guaranteed across other implementations of Python.

As of Python 3.7, this is a guaranteed language feature, not merely an implementation detail.

Activity

mcmwebsol

mcmwebsol commented on Feb 22, 2024

@mcmwebsol

I think Section 11.1 should be updated regarding this.

AllenDowney

AllenDowney commented on Feb 22, 2024

@AllenDowney
Owner
mcmwebsol

mcmwebsol commented on Feb 22, 2024

@mcmwebsol

As of Python 3.7 it's part of the Python language specification. https://docs.python.org/3/whatsnew/3.7.html -
"the insertion-order preservation nature of dict objects has been declared to be an official part of the Python language spec."

Also from https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects -
"Dictionaries preserve insertion order. Note that updating a key does not affect the order. Keys added after deletion are inserted at the end."

AllenDowney

AllenDowney commented on Feb 22, 2024

@AllenDowney
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @AllenDowney@mcmwebsol@gbnewb

        Issue actions

          Dict is now ordered. Maybe the book should be updated? · Issue #95 · AllenDowney/ThinkPython2