0

Explaining this could be hard. I have a very long and complicated script. The final product of this script is a nested dictionary (normal dict, not OrderedDict).

What I cannot explain is that when I run the script on a local machine, the dictionary has always the same structure (keys, values and nested keys and values). When I run the same script on a server I don't get any error, but the dictionary structure changes every time (randomly). Keys are always in a different position and so nested keys and values.

Any ideas why this is happening?

Can it be a different python version? On the local machine python3.6 and on the server 3.5

matteo
  • 4,683
  • 9
  • 41
  • 77
  • 1
    and potentially https://stackoverflow.com/q/30585108/1358308 as you're using older versions of Python – Sam Mason Jan 08 '19 at 17:41
  • 2
    Yes, Python dictionaries before Python 3.7 are *inherently* unordered. In Python 3.6, insertion order was an implementation detail, and in 3.7+ it is part of the standard. – juanpa.arrivillaga Jan 08 '19 at 17:41

1 Answers1

3

Yes, see here (under .values()):

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

user24343
  • 892
  • 10
  • 19