美文网首页
python字典迭代顺序问题

python字典迭代顺序问题

作者: 泰兰德的加长香蕉 | 来源:发表于2018-09-28 10:46 被阅读0次

  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字典迭代顺序问题

      本文链接:https://www.haomeiwen.com/subject/kxuvcxtx.html