I'm making dictionary:
d = {"server":"mpilgrim", "database":"master"}
d['mynewkey'] = 'mynewvalue'
But when I display it I saw that this dict is reversed.
print(d)
{'mynewkey': 'mynewvalue', 'database': 'master', 'server': 'mpilgrim'}
How to reverse it back?
Or if it is true that dictionary is not sortable what I must to use to have collection where the order of that informations matters?
from collections import OrderedDict
d = OrderedDict()
d["server"] = "mpilgrim"
d["database"] = "master"
d['mynewkey'] = 'mynewvalue'
print(d)
OrderedDict([('server', 'mpilgrim'), ('database', 'master'), ('mynewkey', 'mynewvalue')])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With