Dictionary order (Is it consistent up to py3.3 unless using -R or PYTHONHASHSEED is set)

Jon Ribbens jon+usenet at unequivocal.eu
Sun May 28 10:15:48 EDT 2017


On 2017-05-28, Steve D'Aprano <steve+python at pearwood.info> wrote:
> What exactly did you think I got wrong?

3.6 does preserve the dict order. It isn't a guarantee so may change
in future versions, but it is what 3.6 actually does.

>> If you're asking "given a fixed Python version, and where appropriate
>> PYTHONHASHSEED=0, will dictionaries created the same way always
>> iterate in the same order"
>
> Why on earth would you assume a fixed Python version when the OP *explicitly*
> asks about Python 2.7 through 3.3? That's two major versions, four minor
> versions (excluding 3.0, which nobody should use), and who knows how many bug
> fix versions. Since the iteration order is explicitly subject to change, then
> it is possible for any release (major, minor or bug fix) to change the
> iteration order.

Not when you run the same program repeatedly under the same version.
Sure, it might be different if you run it under a different version,
but it's entirely possible for that not to be the guarantee the OP
is looking for.



More information about the Python-list mailing list