def deep_equal(d1, d2):
    """ Deep comparison """
if type(d1) != type(d2):
    return False
if isinstance(d1, dict):
    return all(ddeep_equal(d1.get(k), d2.get(k)) for k in set(list(d1.keys()) +
        list(d2.keys())))
return d1 == d2
Efficient comparison of all elements of python dict