Skip to content

Section 12.1 Dictionaries: As of Python 3.7, dictionaries are ordered. #281

@sheggen

Description

@sheggen

Is your feature request related to a problem? Please describe.
Yes, there is some unclear/vague language around dictionaries being ordered/unordered. In Section 12.1, second paragraph, the book reads:

"Dictionaries are a different kind of collection. They are Python’s built-in mapping type. A map is an unordered, associative collection. The association, or mapping, is from a key, which can be any immutable type, to a value, which can be any Python data object."

The bold text is vague. Maps (not in Python, but the generic hash map or hash table which Python dictionaries are built upon) are unordered, making this statement true. However, dictionaries are a slightly different implementation of hashmaps, which has been ordered as of Python 3.7:

"the insertion-order preservation nature of dict objects has been declared to be an official part of the Python language spec."

The chapter goes on to discuss this unordered nature, which is now also false (it may also appear in later sections, but I did not comb them all):

"The order of the pairs may not be what you expected. Python uses complex algorithms, designed for very fast access, to determine where the key-value pairs are stored in a dictionary. For our purposes we can think of this ordering as unpredictable."

The order will always be insertion-ordered now, and is predictable.

Describe the solution you'd like
Either clarification of when the book is a) describing a generic hashmap/hashtable/map, or a specific Python dictionary; or b) removal of the language about dictionaries being unordered. I believe the former is a better solution, as it will matter to students after this introduction to Python, such as when they learn hash tables in a Data Structures course.

Additional context
Link to the exact text

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions