I have a python dictionary:
d = {'a1': 123, 'a2': 2, 'a10': 333, 'a11': 4456}
When I sort the dictionary using OrderedDict , I get the following output:
from collections import OrderedDict OrderedDict(sorted(d.items())) # Output # OrderedDict([('a1', 123), ('a10', 333), ('a11', 4456), ('a2', 2)])
Is there a way to get it in natural order:
OrderedDict([('a1', 123), ('a2', 2), ('a10', 333), ('a11', 4456)]) or {'a1': 123, 'a2': 2, 'a10': 333, 'a11': 4456}
Thanks.
source share