Update: dicts retaining insertion order is guaranteed for Python 3.7+
I want to use a .py file like a config file.
So using the {.
As of python 3.6, all dictionaries will be ordered by default. For now, this is an implementation detail of dict
and should not be relied upon, but it will likely become standard after v3.6.
Insertion order is always preserved in the new dict
implementation:
>>>x = {'a': 1, 'b':2, 'c':3 }
>>>list(x.keys())
['a', 'b', 'c']
As of python 3.6 **kwargs
order [PEP468] and class attribute order [PEP520] are preserved. The new compact, ordered dictionary implementation is used to implement the ordering for both of these.