You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
the order of dict isn't documented in an example #133361
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}.
So they might feel confused and think {one: 1, two: 2} shoudn't be equal to {two:2, one:1}.
Why? They could read the rest of dict docs on same page:
Dictionaries compare equal if and only if they have the same (key, value) pairs (regardless of ordering). Order comparisons (‘<’, ‘<=’, ‘>=’, ‘>’) raise TypeError.
Explain what? What's unclear in the above sentence?
I'm not sure if it is right. Some important things like the order of dict should say first. It shouldn't be after its methods. This might be more friendly for new users.
"it" refers to the example instead of the above sentence.
Ok. Examples here are to illustrate dict() constructor. And there are several cases, which differ by ordering of keys. I doubt that adding something does make sense here.
Dicts became ordered (by insertion), not unordered, in 3.6/7. And it is documented: Dictionaries preserve insertion order. Note that updating a key does not affect the order. Keys added after deletion are inserted at the end." This is followed by examples and version note. Nothing more is needed.
I think the following explains equality quite sufficiently, but should be moved before the example.
Dictionaries compare equal if and only if they have the same (key, value) pairs (regardless of ordering). Order comparisons (‘<’, ‘<=’, ‘>=’, ‘>’) raise TypeError.
I am reopening to move the explanation of == before its use.
Activity
skirpichev commentedon May 4, 2025
Why? They could read the rest of dict docs on same page:
Yzi-Li commentedon May 4, 2025
Oh, it mentions in
values()and I just realized this. Would it be better if we explain for it?skirpichev commentedon May 4, 2025
It's just after description of dict's methods.
Explain what? What's unclear in the above sentence?
Yzi-Li commentedon May 4, 2025
Yes, you're right. I didn't notice the indent.
I'm not sure if it is right. Some important things like the order of dict should say first. It shouldn't be after its methods. This might be more friendly for new users.
Yzi-Li commentedon May 4, 2025
"it" refers to the example instead of the above sentence.
skirpichev commentedon May 4, 2025
Ok. Examples here are to illustrate dict() constructor. And there are several cases, which differ by ordering of keys. I doubt that adding something does make sense here.
terryjreedy commentedon May 4, 2025
Dicts became ordered (by insertion), not unordered, in 3.6/7. And it is documented: Dictionaries preserve insertion order. Note that updating a key does not affect the order. Keys added after deletion are inserted at the end." This is followed by examples and version note. Nothing more is needed.
I think the following explains equality quite sufficiently, but should be moved before the example.
I am reopening to move the explanation of == before its use.
Yzi-Li commentedon May 4, 2025
Do you need me to create a PR to move this explanation?
gh-133361: move the explanation of dict equal before its use (#133424)
pythongh-133361: move the explanation of dict equal before its use (p…
pythongh-133361: move the explanation of dict equal before its use (p…
[3.14] gh-133361: move the explanation of dict equal before its use (G…
[3.13] gh-133361: move the explanation of dict equal before its use (G…
pythongh-133361: move the explanation of dict equal before its use (p…