Skip to content

the order of dict isn't documented in an example #133361

Closed
@Yzi-Li

Description

@Yzi-Li

Documentation

I am reading the documentation of dictionary.
There is an example

>>> a = dict(one=1, two=2, three=3)
>>> b = {'one': 1, 'two': 2, 'three': 3}
>>> c = dict(zip(['one', 'two', 'three'], [1, 2, 3]))
>>> d = dict([('two', 2), ('one', 1), ('three', 3)])
>>> e = dict({'three': 3, 'one': 1, 'two': 2})
>>> f = dict({'one': 1, 'three': 3}, two=2)
>> a == b == c == d == e == f
True

For new users, they might not know that the dictionary is unorderd in 3.7+ (not everyone reads data model before reading this). So they might feel confused and think {one: 1, two: 2} shoudn't be equal to {two:2, one:1}.

Maybe we could link date model for explaning.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions