Python: Compare Dictionaries

def compareDicts(d1, d2):
differences = []
# present in d1 but not in d2
for key, value in ({k: d1[k] for k in set(d1) set(d2)}).iteritems():
temp = list[[key, value], None]
# present in d2 but not in d1
diff2 = {k: d2[k] for k in set(d2) set(d1)}
for key, value in (diff2).iteritems():
temp = [None, [key, value]]
# updated from d1 to d2
updatedKeys = [item for item in list(set(d1.keys()) & set(d2.keys())) if d1.get(item) != d2.get(item)]
for key in updatedKeys:
temp = [[key, d1.get(key)],[key, d2.get(key)]]
return differences

view raw

hosted with ❤ by GitHub

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s