Fix Python – Right way to initialize an OrderedDict using its constructor such that it retains order of initial data?

What’s the correct way to initialize an ordered dictionary (OD) so that it retains the order of initial data?
from collections import OrderedDict

# Obviously wrong because regular dict loses order
d = OrderedDict({‘b’:2, ‘a’:1})

# An OD is represented by a list of tuples, so would this work?
d = OrderedDict([(‘b’,2), (‘a’, 1)])

# What about us….

Fix Python – How to convert an OrderedDict into a regular dict in python3

I am struggling with the following problem:
I want to convert an OrderedDict like this:
OrderedDict([(‘method’, ‘constant’), (‘data’, ‘1.225’)])

into a regular dict like this:
{‘method’: ‘constant’, ‘data’:1.225}

because I have to store it as string in a database. After the conversion the order is not important anymore, so I can spare the ordere….

Fix Python – Converting dict to OrderedDict

I am having some trouble using the collections.OrderedDict class. I am using Python 2.7 on Raspbian, the Debian distro for Raspberry Pi. I am trying to print two dictionaries in order for comparison (side-by-side) for a text-adventure. The order is essential to compare accurately.
No matter what I try the dictionaries print in their usual unordere….