python dictionary intersection code example
Example 1: python list INTERSECTION
a = ['apple', 'banana', 'pear']
b = ['fridge', 'stove', 'banana']
a & b == ['banana'] #True
Example 2: intersection python dict
Python 3.6.9 (default, Oct 8 2020, 12:12:24)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = {'a': 123, 'c': 5}
>>> b = {'a': 2, 'b': 4}
>>> a.keys() & b.keys() # intersection
{'a'}
>>> a.keys() ^ b.keys() # difference
{'b', 'c'}
>>> a.keys() - b.keys() # subtraction
{'c'}