When I use the dict() the order is changed! How to get the dict follow the order of OrderedDict()?
>>> from collections import OrderedDict
>>> OrderedDict([('method', 'constant'), ('data', '1.225')])
OrderedDict([('method', 'constant'), ('data', '1.225')])
>>> dict(OrderedDict([('method', 'constant'), ('data', '1.225')]))
{'data': '1.225', 'method': 'constant'}
>>>
What I would like to get is the same order as OrderedDict():
{'method': 'constant','data': '1.225'}
If cannot convert, how to parse the OrderedDict such as
for key, value in OrderedDict....
If you just want to print out
dictin order without theOrderedDictwrapper you can usejson:You can iterate an
OrderedDictidentically to adict: