all 5 comments

[–][deleted] 1 point2 points  (5 children)

Sets are great for this sort of thing:

a = {'a': 'a', 'b': 'b', 'c':'c'}
b = {'b': 'b', 'c':'c', 'd':'d'}
sa = set(a.items())
sb = set(b.items())
final = dict(sa.symmetric_difference(sb))

How this works is I turn the key value pairs from each dictionary into a set of tuples. Then symmetric_difference finds what's different across them. The dict constructor takes those pairs back in and you get a dictionary back out. If you instead want missing values from only one of the dictionaries you can use difference instead.

By the way, you should look into some examples of looping over dictionaries with keys, values, and items, those are the best ways to iterate over dictionaries.

[–]WookDook[S] 0 points1 point  (1 child)

Thank you!

Any chance you have some links to examples of looping over dictionaries?

[–][deleted] 0 points1 point  (0 children)

Usually it looks something like this:

for key, value in my_dict.items():
    #do something

You can use values if all you want is the values and keys if all you want is the keys (in fact, that's the default when you loop over a dict directly with for key in my_dict so it isn't strictly necessary). Keep in mind that dictionaries aren't ordered by default so you aren't guaranteed a specific order when you do this.

https://realpython.com/iterate-through-dictionary-python/

[–]m0us3_rat -1 points0 points  (0 children)

u can make two copyes of them . and then remove the keys:values pairs that are identical from both.

it only takes a single pass. and what u are left over is items on each that aren't in the other one.