python : how to disable auto sort when creating dictionary

后端 未结 3 1500
情歌与酒
情歌与酒 2021-01-05 01:12

i need help for this case :

m={}
m[1]=1
m[333]=333
m[2]=2

# Result:
{1: 1, 2: 2, 333: 333}

so even when i didn\'t enter \'333\' the last,

3条回答
  •  余生分开走
    2021-01-05 01:23

    Items stored in a dictionary do not have any inherent order. The order they are printed out is entirely down to the hash values for each of the keys and the other items in the dictionary.

提交回复
热议问题