import difflib
import pprint

def compare_dicts(d1, d2):
    return '\n' + '\n'.join(difflib.ndiff(pprint.pformat(d1).splitlines(),
        pprint.pformat(d2).splitlines()))
Print diff of Python dictionaries