为什么字典排序是非确定性的?我最近从Python 2.7切换到Python 3.3,似乎在Python 2中,字典键的排序是任意的但是一致的,在Python 3中,用例如获得的字典的键的排序vars()看起来是非确定性的。如果我跑:class Test(object): passparameters = vars(Test)print(list(parameters.keys()))在Python 2.7和Python 3.3中,然后:Python 2.7一直给我['__dict__', '__module__', '__weakref__', '__doc__']使用Python 3.3,我可以得到任何随机顺序 - 例如:['__weakref__', '__module__', '__qualname__', '__doc__', '__dict__']['__doc__', '__dict__', '__qualname__', '__module__', '__weakref__']['__dict__', '__module__', '__qualname__', '__weakref__', '__doc__']['__weakref__', '__doc__', '__qualname__', '__dict__', '__module__']这种非决定论来自哪里?为什么会这样list({str(i): i for i in range(10)}.keys())......在跑步之间保持一致,总是给予['3', '2', '1', '0', '7', '6', '5', '4', '9', '8']......?
添加回答
举报
0/150
提交
取消
