python字典迭代顺序问题

  Before Python 3.6 a regular dict did not track the insertion order, and iterating over it produced the values in order based on how the keys are stored in the hash table, which is in turn influenced by a random value to reduce collisions. In an OrderedDict, by contrast, the order in which the items are inserted is remembered and used when creating an iterator.

  Under Python 3.6, the built-in dict does track insertion order, although this behavior is a side-effect of an implementation change and should not be relied on.

use collections.OrderedDict instead!

你可能感兴趣的:(python字典迭代顺序问题)