def dict_cmp(A, B):
    if len(A) != len(B):
        return cmp(len(A), len(B))
adiff = smallest_diff_key(A, B)
bdiff = smallest_diff_key(B, A)
if adiff != bdiff:
    return cmp(adiff, bdiff)
return cmp(A[adiff], b[bdiff])
Is there a description of how __cmp__ works for dict objects in Python 2?