How do I test dictionary-equality with Python’s doctest-package?

Another good way is to use pprint (in the standard library).

>>> import pprint
>>> pprint.pprint({"second": 1, "first": 0})
{'first': 0, 'second': 1}

According to its source code, it’s sorting dicts for you:

http://hg.python.org/cpython/file/2.7/Lib/pprint.py#l158

items = _sorted(object.items())

Leave a Comment