In [1]:
a = {
'x' : 1,
'y' : 2,
'z' : 3 }
b = {
'w' : 10,
'x' : 11,
'y' : 2 }
In [2]:
# Find keys in common
a.keys() & b.keys() # { 'x', 'y' }
Out[2]:
In [3]:
# Find keys in a that are not in b
a.keys() - b.keys() # { 'z' }
Out[3]:
In [4]:
# Find (key,value) pairs in common
a.items() & b.items() # { ('y', 2) }
Out[4]:
In [6]:
# Make a new dictionary with certain keys removed
c = {key:a[key] for key in a.keys() - {'z', 'w'}}
# c is {'x': 1, 'y': 2}
print(c)