Answers for "compare strings based on order in dictionary python"

4

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)
Posted by: Guest on April-04-2021
0

how to compare values in dictionary with same key python

if (key in dictionary2 and dictionary1[key] == dictionary2[key]):
Posted by: Guest on December-11-2021

Code answers related to "compare strings based on order in dictionary python"

Python Answers by Framework

Browse Popular Code Answers by Language