python : how to disable auto sort when creating dictionary

dictionary, python, sorting

Solution

It is not sorting. `dict` is not ordered at all, so you cannot influence the key order in any way. There is `collections.OrderedDict` in 2.7 and 3.1+, there is also standalone module for 2.4-2.6.

Problem

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, i got this '333' listed in the end of the dictionary when print it out. why is this 'dictionary' doing auto sort? and how disable it? i can creata a function to re-sort to fix the order. but that's not what i want, i just simply want to print and get output order just like the order when i input the data. Is there any good explanation and is there any solution ?

Original source

Related problems