Compare two nested dictionaries
John Nagle
nagle at animats.com
Mon Jul 26 13:08:43 EDT 2010
On 7/25/2010 8:03 AM, targetsmart wrote:
> Hi,
> I am trying to compare two nested dictionaries, I want to know what is
> the exact difference between them.
d1 = {'a' : 1, 'b' : 2, 'c': 3 }
d2 = {'a' : 1, 'b' : 3, 'd': 4 }
diff = dict(set(d1.items()) - set(d2.items()))
print (diff)
{'c': 3, 'b': 2}
That's the true "difference", with all entries in d1 not
identically in d2 listed. Is that what you wanted?
John Nagle
More information about the Python-list
mailing list