[issue21691] set() returns random output with Python 3.4.1, in non-interactive mode
Ned Deily
report at bugs.python.org
Sun Jun 8 08:58:31 CEST 2014
Ned Deily added the comment:
To expand a bit, this is by design, a consequence of the hash randomization feature; see
https://docs.python.org/3/using/cmdline.html#envvar-PYTHONHASHSEED
As noted there, if necessary, it is possible to disable hash randomization. But tests with set values or dict keys should not depend on a particular order as even disabling hash randomization would not guarantee the same results on different platforms or builds of Pythons.
$ python3.4 -c "print(set(['A', 'B']))"
{'B', 'A'}
$ python3.4 -c "print(set(['A', 'B']))"
{'A', 'B'}
$ python3.4 -c "print(set(['A', 'B']))"
{'B', 'A'}
$ PYTHONHASHSEED=0 python3.4 -c "print(set(['A', 'B']))"
{'B', 'A'}
$ PYTHONHASHSEED=0 python3.4 -c "print(set(['A', 'B']))"
{'B', 'A'}
$ PYTHONHASHSEED=0 python3.4 -c "print(set(['A', 'B']))"
{'B', 'A'}
----------
nosy: +ned.deily
stage: -> resolved
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21691>
_______________________________________
More information about the Python-bugs-list
mailing list