I have a dictionary like this say:
a = {'first': 1, 'second': 2, 'third': 3}
Now when I print it prints in an very random order. Whereas I need it to preserve the order always. How can I go about doing this in python?
I have a dictionary like this say:
a = {'first': 1, 'second': 2, 'third': 3}
Now when I print it prints in an very random order. Whereas I need it to preserve the order always. How can I go about doing this in python?
Use OrderedDict class. Example below.
from collections import OrderedDict
dict=OrderedDict()
dict['first']=1
dict['second']=2
dict['third']=3
dict