Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

find commonalities in dictionary python

# How to find commonalities in two dictionaries (same keys, same values, etc)
a = {
    'x': 1,
    'y': 2,
    'z': 3
}
b = {
    'w': 10,
    'x': 11,
    'y': 2
}
# find keys in common 
print(a.keys() & b.keys()) # {'x', 'y'}
# find keys in a that are not in b 
print(a.keys() - b.keys()) # {'z'}
# find (key, value) pairs in common 
print(a.items() & b.items()) # {('y', 2)} 
 
PREVIOUS NEXT
Tagged: #find #commonalities #dictionary #python
ADD COMMENT
Topic
Name
7+4 =