This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: comparison problem of two 'dict' objects
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, singer
Priority: normal Keywords:

Created on 2012-12-06 11:29 by singer, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg177039 - (view) Author: Singer Song (singer) Date: 2012-12-06 11:29
#python code:
a={600072:1, 80000880:2, 600243:3, 600495:4, 80002529:5}
b={600072:1, 80000880:2, 600243:3, 80002529:5, 600495:4}
print(a)
print(b)
print(a==b)
print(str(a)==str(b))
print(a.keys()==b.keys())

#output in python2.7.3:
{600072: 1, 80000880: 2, 600243: 3, 80002529: 5, 600495: 4}
{600072: 1, 80000880: 2, 600243: 3, 600495: 4, 80002529: 5}
True
False
False

#output in python3.2.3:
{600072: 1, 80000880: 2, 600243: 3, 80002529: 5, 600495: 4}
{600072: 1, 80000880: 2, 600243: 3, 600495: 4, 80002529: 5}
True
False
True

#two questions:
1)str(a) and str(b) are different, why?
2)keys method returns different result between python2.7.3 and python3.2.3
msg177040 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-12-06 11:32
That's because dicts are not ordered.  You might want to use collections.OrderedDict if the order matters to you.
History
Date User Action Args
2022-04-11 14:57:39adminsetgithub: 60831
2012-12-06 11:32:20ezio.melottisetstatus: open -> closed

nosy: + ezio.melotti
messages: + msg177040

resolution: not a bug
stage: resolved
2012-12-06 11:29:27singercreate