Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

compare two dictionaries in python

def dict_compare(d1, d2):
    d1_keys = set(d1.keys())
    d2_keys = set(d2.keys())
    shared_keys = d1_keys.intersection(d2_keys)
    added = d1_keys - d2_keys
    removed = d2_keys - d1_keys
    modified = {o : (d1[o], d2[o]) for o in shared_keys if d1[o] != d2[o]}
    same = set(o for o in shared_keys if d1[o] == d2[o])
    return added, removed, modified, same

x = dict(a=1, b=2)
y = dict(a=2, b=2)
added, removed, modified, same = dict_compare(x, y)
Comment

how to compare values in dictionary with same key python

if (key in dictionary2 and dictionary1[key] == dictionary2[key]):
Comment

PREVIOUS NEXT
Code Example
Python :: pip offline package install 
Python :: python opencv load image 
Python :: python codes 
Python :: python opérateur ternaire 
Python :: Longest Common Prefix Method 2 
Python :: how do a plot on matplotlib python 
Python :: pip install mod_wsgi error 
Python :: install apriori package python 
Python :: anaconda 
Python :: append a list to a list python 
Python :: python check array exists 
Python :: how to change the disabled color in tkinter 
Python :: python *args 
Python :: python program to print inverted star pattern 
Python :: if string in list python 
Python :: how to set gpu python 
Python :: log log grid python 
Python :: pandas read csv without scientific notation 
Python :: python command line start server 
Python :: lambda and function in python 
Python :: find prime in python list 
Python :: how to check django version 
Python :: pandas load feather 
Python :: python sum of a subset 
Python :: compile python to exe bash 
Python :: raw input example py 
Python :: str to datetime time 
Python :: format date string python 
Python :: Converting Dataframe from list Using a list in the dictionary 
Python :: pandas parallelize for loop 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =