Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_dictionary_is_unordered in about_dictionaries.py doesn't test what it says it tests #240

Open
jpretori opened this issue Jul 25, 2021 · 3 comments

Comments

@jpretori
Copy link

I'm using Python 3.8.5.

According to official Python docs (https://docs.python.org/3.8/library/stdtypes.html#mapping-types-dict):

Changed in version 3.7: Dictionary order is guaranteed to be insertion order. This behavior was an implementation detail of CPython from 3.6.

So technically, in test_dictionary_is_unordered(), dict1 == dict2 should always return False. It doesn't for some reason I can't seem to work out.

Playing around with the Python console:

>>> d1
{1: 1, 2: 2, 3: 3}
>>> d2
{2: 2, 1: 1, 3: 3}
>>> d1 == d2
True
>>> l1
[1, 2, 3]
>>> l2
[2, 1, 3]
>>> l1 == l2
False

I guess maybe this means that == means something slightly different for dict than I expected?

@programmer-ke
Copy link

programmer-ke commented Apr 5, 2022

I guess maybe this means that == means something slightly different for dict than I expected?

This is what is said in the official docs: https://docs.python.org/3.8/library/stdtypes.html#mapping-types-dict

Dictionaries compare equal if and only if they have the same (key, value) pairs (regardless of ordering). Order comparisons (‘<’, ‘<=’, ‘>=’, ‘>’) raise TypeError

So it should behave differently than in lists where order matters.

@warriorwizard
Copy link

I think the case may be
Since there is no index in dictionary introduces then whats the point of comparing the elements in index way, the order preservence was just to make retrival easy

@HeavenEvolved
Copy link

HeavenEvolved commented Mar 16, 2023

We could compare the enumerate of both dicts to solve the issue. Since it will return a list of tuples and would check as a list. Would be happy to work on this. Not sure who to tag to be assigned to this issue.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants