# Comparing Unequal Dictionaries

**URL:** <https://discourse.julialang.org/t/comparing-unequal-dictionaries/52048>\
**Category:** New to Julia\
**Created:** [December 18, 2020, 2:35pm UTC](https://discourse.julialang.org/t/comparing-unequal-dictionaries/52048 "2020-12-18T14:35:00Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Rudi79](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rudi79/32/3884_2.png) [@Rudi79](https://discourse.julialang.org/u/Rudi79)\
**Post date:** [December 18, 2020, 3:10pm UTC](https://discourse.julialang.org/t/comparing-unequal-dictionaries/52048/2 "2020-12-18T15:10:09Z")

</div>

It depends on what you want. What should the difference be if one key is not present in both dicts?  
Assuming a default value of 0, the result could look something like

```julia
difference = sum(values(mergewith( (x,y) -> abs(x-y), a, b)))

```

Or a bit more verbose so you can better see what is going on could be:

```julia
diff = 0
same = intersect(keys(a), keys(b))
for i in same
    diff += abs(a[i]-b[i])
end
for i in setdiff(keys(a), same)
    diff += a[i]
end
for i in setdiff(keys(b), same)
    diff += b[i]
end

```

I would also like to suggest reading this post:

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

_[View the full topic](https://discourse.julialang.org/t/comparing-unequal-dictionaries/52048)._
