# Broadcast \[possibly missing\] key value pairs from one Dict to another?

**URL:** <https://discourse.julialang.org/t/broadcast-possibly-missing-key-value-pairs-from-one-dict-to-another/49425>\
**Category:** New to Julia\
**Tags:** broadcast, dictionary, broadcasting\
**Created:** [November 1, 2020, 8:02pm UTC](https://discourse.julialang.org/t/broadcast-possibly-missing-key-value-pairs-from-one-dict-to-another/49425 "2020-11-01T20:02:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkarikom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkarikom/32/7096_2.png) [@mkarikom](https://discourse.julialang.org/u/mkarikom)\
**Post date:** [November 1, 2020, 8:02pm UTC](https://discourse.julialang.org/t/broadcast-possibly-missing-key-value-pairs-from-one-dict-to-another/49425/1 "2020-11-01T20:02:15Z")

</div>

How can I broadcast key value pairs from one Dict to another, whether or not they exist?

Tried the following but it doesn’t work:

```julia
check = Dict()
check2 = Dict(:a=>1,:b=>"b")
check[keys(check2).=values(check2)]
@test get(check,:a,"") == 1 && get(check,:b,"") == "b"

ERROR: KeyError: key Pair{Symbol,B} where B[:a => 1, :b => "b"] not found
Stacktrace:
 [1] getindex(::Dict{Any,Any}, ::Array{Pair{Symbol,B} where B,1}) at ./dict.jl:467
 [2] top-level scope at /home/au/code/BioPAXwork/local/pcquery/Ex_annotate_seurat.jl:71

```

Broadcasting seems readable and efficient by if there is a better way to update one Dict with another that’s great too.

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [November 1, 2020, 8:56pm UTC](https://discourse.julialang.org/t/broadcast-possibly-missing-key-value-pairs-from-one-dict-to-another/49425/2 "2020-11-01T20:56:28Z")

</div>

You can’t broadcast per-se but you can very easily do something like

```julia
[check[k] = v for (k,v) in check2]

```

It’s not clear though whether your question matches the example you’ve written, so I’m not sure if the above actually helps…

Edit:  
You can also use `merge` and `union` (and their `!` counterparts)

---

<div class="post-metadata">

**Author:** ![mkarikom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkarikom/32/7096_2.png) [@mkarikom](https://discourse.julialang.org/u/mkarikom)\
**Post date:** [November 1, 2020, 8:57pm UTC](https://discourse.julialang.org/t/broadcast-possibly-missing-key-value-pairs-from-one-dict-to-another/49425/3 "2020-11-01T20:57:31Z")

</div>

perfect, thanks
