How to compare only the values of two dictonaries?
So I have this:
dict1 = {"appe": 3962.00, "waspeen": 3304.08}
dic2 = {"appel": 3962.00, "waspeen": 3304.08}
def compare_value_dict(dic):
return dic
def compare_value_dict2(dic2):
return dic2
def compare_dic(dic1, dic2):
if dic1 == dic2:
print('the same dictionary')
else:
print('difference dictionary')
compare_dic(compare_value_dict(dict1).values(), compare_value_dict2(dic2.values()))
this works:
compare_dic(compare_value_dict(dict1).keys(), compare_value_dict2(dic2.keys()))
Good theory explanation give by @Martijn post. Here is a simple way to compare 2 dict values if they are having same keys:
To compare only the similar keys they the dict instance are from different dicts:
The returned difference list contains the different key not the values. In order to have value simply switch the first
k
withv
Second method is utilizing sets: