You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
659 B
Python
37 lines
659 B
Python
def dictDiff(a : dict, b : dict):
|
|
|
|
a_keys = set(a.keys())
|
|
b_keys = set(b.keys())
|
|
|
|
a_only = a_keys - b_keys
|
|
b_only = b_keys - a_keys
|
|
a_b = a_keys & b_keys
|
|
|
|
changed = {k for k in a_b if a[k] != b[k]}
|
|
|
|
diffResult = {}
|
|
|
|
if a_only:
|
|
diffResult['removed'] = a_only
|
|
if b_only:
|
|
diffResult['added'] = b_only
|
|
if changed:
|
|
diffResult['changed'] = changed
|
|
|
|
return diffResult
|
|
|
|
|
|
def setDiff(a : set, b : set) -> set:
|
|
|
|
a_only = a - b
|
|
b_only = b - a
|
|
|
|
diffResult = {}
|
|
|
|
if a_only:
|
|
diffResult['removed'] = a_only
|
|
if b_only:
|
|
diffResult['added'] = b_only
|
|
|
|
return diffResult
|