Why dictionary values aren't in the inserted order?

前端 未结 6 859
野的像风
野的像风 2020-12-19 02:37

When i declare a list 1,2,3,4 and i do something with it , even just print i get back the same sequence 1,2,3,4.

But when i do anything with dictionaries , they alw

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-19 02:45

    Dictionaries in Python are unordered by definition. Use OrderedDict if you need the order in which values were inserted (it's available in Python 2.7 and 3.x).

提交回复
热议问题