Search
 
SCRIPT & CODE EXAMPLE
 

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)} 
Comment

PREVIOUS NEXT
Code Example
Python :: multiprocessing pool pass additional arguments 
Python :: ForeignKey on delete django 
Python :: Django migrations when table already exist in database 
Python :: create file in a specific directory python 
Python :: pandas reset index from 0 
Python :: plot data python 
Python :: how to combine strings python 
Python :: Python dir() built-in function 
Python :: find word position in string python 
Python :: how to separate url from text in python 
Python :: import flask session 
Python :: numpy array serialize to string 
Python :: regex_2/_regex.c:50:10: fatal error: Python.h: No such file or directory 
Python :: pygame collisions 
Python :: creating an apis with python and flask 
Python :: python comparison operators 
Python :: tkinter frameless window 
Python :: classification cross validation 
Python :: serialization in django 
Python :: how to encode emoji to text in python 
Python :: python flask api 
Python :: len function in python 
Python :: how to make an array in python 
Python :: List Delete a Element 
Python :: how to set a single main title above all the subplots with pyplot 
Python :: matplotlib remove duplicate legend entries from plotting loop 
Python :: how to install httplib in python 
Python :: use mongo replica set python 
Python :: what is django 
Python :: how to get the year and month in python 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =