Python字典在字典中切换键

Jus*_*som 2 python dictionary

所以我在python中有一个字典,其中我有一个数字用于键,其值为attatched.

myDictionary = {"0" :0, "1":0, "2":0, "3":0, "4":0, "5":0, "6":12, "7":0,"8":0,"9":0,"10":0,"11":0, "12":0,"13":12}
Run Code Online (Sandbox Code Playgroud)

我运行的doctest说:

>>> myDictionary = {"0" :0, "1":0, "2":0, "3":0, "4":0, "5":0, "6":12, "7":0,"8":0,"9":0,"10":0,"11":0, "12":0,"13":12}
>>> new_Val = 0
>>> method0 = WordClass (new_Val, myDictionary)
True
Run Code Online (Sandbox Code Playgroud)

我正在做一些调试广告,打印出我的字典,以确保我在字典中查看正确的值.当我打印出来时,它看起来像这样:

{'11': 4, '10': 4, '13': 0, '12': 4, '1': 4, '0': 4, '3': 4, '2': 4, '5': 4, '4': 4, '7': 4, '6': 0, '9': 4, '8': 4}
Run Code Online (Sandbox Code Playgroud)

它们全都乱了.默认情况下,python在存储内存时会这样做吗?如果是这样,我可以在某处查看某些文档吗?

谢谢

小智 5

python中的字典是无序的.你真的需要订单吗?如果你详细说明这一点,人们可能会帮助你更多.如果您真的需要订购,可以尝试使用https://docs.python.org/2/library/collections.html#collections.OrderedDict之类的东西.