value = { k : second_dict[k] for k in set(second_dict) - set(first_dict) }
def dict_compare(d1, d2):
d1_keys = set(d1.keys())
d2_keys = set(d2.keys())
shared_keys = d1_keys.intersection(d2_keys)
added = d1_keys - d2_keys
removed = d2_keys - d1_keys
modified = {o : (d1[o], d2[o]) for o in shared_keys if d1[o] != d2[o]}
same = set(o for o in shared_keys if d1[o] == d2[o])
return added, removed, modified, same
x = dict(a=1, b=2)
y = dict(a=2, b=2)
added, removed, modified, same = dict_compare(x, y)
if (key in dictionary2 and dictionary1[key] == dictionary2[key]):
# Comparing lists and dictionaries
# We create an empty list and an empty dictionary
lst = [] # Other way is lst = list()
dictionary = {} # Other way is dictionary = dict()
# adding items to the list
lst.append(25)
lst.append(34)
print(lst) # Output: [25, 34]
# adding values to a dictionary using keys
dictionary['first'] = 25
dictionary['second'] = 34
print(dictionary) # Output: {'first': 25, 'second': 34}
# Change an item using index in list
lst[0] = 23
print(lst) # Output: [23, 34]
# Change a value using key in dictionary
dictionary['first'] = 34
print(dictionary) # Output: {'first': 34, 'second': 34}