I've found a nice workaround for this problem, which is building a frozenset containing the dictionary items:
EDIT: this answer was written before/around the time keeping dictionary's insertion order became a feature. The provided code will lose the ordering, which is irrelevant for Python < 3.6.
>>> a = {'key1' : 'val1', 'key2' : 'val2'}
>>> b = frozenset(a.items())
>>> frozenset_restored_to_dict = dict(b)
>>> frozenset_restored_to_dict
{'key2': 'val2', 'key1': 'val1'}
As can be seen in the code, b
is a frozenset, which is immutable and hashable, and can be totally restored to be a regular dictionary like a
.