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: Dict items() ordering varies across interpreter invocations
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ddvoinikov, pitrou
Priority: normal Keywords:

Created on 2012-08-01 12:05 by ddvoinikov, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg167116 - (view) Author: Dmitry Dvoinikov (ddvoinikov) Date: 2012-08-01 12:05
The following line prints different things each time you run it:

python3 -c "print(', '.join({ '1': '2', '3': '4' }.keys()))"

The output is either "1, 3" or "3, 1". Is such indeterministic behavior intentional ?

Using Python 3.3.0b1 (default, Aug  1 2012, 06:09:44)
msg167121 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-08-01 12:45
Yes, because hash randomization is now enabled by default:
http://docs.python.org/dev/reference/datamodel.html#object.__hash__

If you want deterministic behaviour, just set e.g. PYTHONHASHSEED=0.
(or any other fixed value)
History
Date User Action Args
2022-04-11 14:57:33adminsetgithub: 59729
2012-08-01 12:45:34pitrousetstatus: open -> closed
resolution: not a bug
2012-08-01 12:45:05pitrousetnosy: + pitrou
messages: + msg167121
2012-08-01 12:05:30ddvoinikovcreate