Python dict.items(): Set operations on key-value pairs

Python dict.items(): Set operations on key-value pairs

Want the unique key-value pairs from two Python dicts? dict.items() returns a set-like object:

d1 = {'a':10, 'b':20, 'c':30}
d2 = {'b':20, 'c':30, 'd':40}
d1.items() | d2.items() 

This returns the unique key-value pairs:

{(‘b’, 20), (‘a’, 10), (‘d’, 40), (‘c’, 30)}