dictionary order

hi guys,
i don’t know why when i insert some keys and values in a dictionary when i print it shows me inverse order
for example:
dict={}
dict[“a”]=1
dict[“b”]=2
print (dict)
---->{b:2,a:1}
this is an example, and if i run this code it returns me te correct order but my code its a little bit more complicated and i really don’t know why it returns me an inverse list ok keys index.
the questions at this point is, how can i invert the dictionary key index maintaining the correct value?
thx

Dicts don’t have an order, lists and tuples do.

Either use a list and put dicts inside if necessary,
maintain a dict + a list of dict keys in the order you need the dict entries,
or use collections.OrderedDict

i tried something using collections,OrderedDict but dunno exactly what it means and blender returns me an error, anyway thx for help

Read the Python documentation about dictionary, this explains all you probably need to know (including how to get the elements of a dict in a sorted manner using the standard dict implementation):
https://docs.python.org/3.4/tutorial/datastructures.html#dictionaries

from collections import OrderedDict

d = OrderedDict()
d.update({"foo": "123"})
d.update({"bar": "456"})

# foo
# bar
for key in d:
    print(key)

# 123
# 456
for value in d.values():
    print(value)

# Key: foo, Value: 123
# Key: bar, Value: 456
for key, value in d.items():
    print("Key: %s, Value: %s" % (key, value))

# Initialize with key-value pairs (same as above d)
d = OrderedDict( (("foo", "123"), ("bar", 456)) ) # tuple of tuples
d = OrderedDict( [["foo", "123"], ["bar", 456]] ) # list of lists

# Initialize from two sequences, one with keys, one with values (same as above d)
keys = ("foo", "bar")
values = (123, 456)
d = OrderedDict(zip(keys, values))

ok thank you