# Lacking keys/values in a dictionary

**URL:** <https://discourse.julialang.org/t/lacking-keys-values-in-a-dictionary/61809>\
**Category:** General Usage\
**Created:** [May 25, 2021, 7:59pm UTC](https://discourse.julialang.org/t/lacking-keys-values-in-a-dictionary/61809 "2021-05-25T19:59:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bonnkleiford](https://avatars.discourse-cdn.com/v4/letter/b/46a35a/32.png) [@bonnkleiford](https://discourse.julialang.org/u/bonnkleiford)\
**Post date:** [May 25, 2021, 7:59pm UTC](https://discourse.julialang.org/t/lacking-keys-values-in-a-dictionary/61809/1 "2021-05-25T19:59:11Z")

</div>

I have 3 dictionaries, A and B:

```julia
A = Dict("1" => 0.1
  "3" => 0.1
  "5" => 0.1
  "7" => 0.1
  "9" => 0.1
  "11" => 0.1
  "13" => 0.1
  "15" => 0.1
  "17" => 0.1
  "19" => 0.1)

B = Dict("1" => 0.2
  "5" => 0.1
  "7" => 0.1
  "9" => 0.1
  "11" => 0.2
  "15" => 0.1
  "17" => 0.2)

C = Dict("1" => 0.1
  "3" => 0.2
  "7" => 0.1
  "9" => 0.2
  "13" => 0.1
  "15" => 0.1
  "17" => 0.1
  "19" => 0.1)

```

If I am going to get a vector/matrix of the values of A, I have to `A = [collect(values(A))]`.

```julia
A = 1-element Vector{Vector{Any}}:
[0.10, 0.10, 0.10, 0.10, 0.10, 0.10, 0.10, 0.10, 0.10, 0.10]

```

If I do the same to Dictionary B:

```julia
B = 1-element Vector{Vector{Any}}:
[0.10, 0.10, 0.10, 0.10, 0.10, 0.10, 0.10]

```

I want to do the same to B and C but Dictionary B does not contain keys/values “3” =\> 0.1, “13” =\> 0.1, “19”=\>0.1 and Dictionary C Dows not contain “5” =\> 0.1, “11” =\> 0.1. What should I do in order to assign ZEROS to the values of the keys in dictionary B and C not found in A. Like this:

```julia
New_B = 1-element Vector{Vector{Any}}:
[0.10, 0, 0.10, 0.10, 0.10, 0.10, 0, 0.10, 0.10, 0]

New_C = 1-element Vector{Vector{Any}}:
[0.10, 0.10, 0 , 0.10, 0.10, 0, 0.10, 0.10, 0.10, 0.10]

```

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [May 25, 2021, 8:11pm UTC](https://discourse.julialang.org/t/lacking-keys-values-in-a-dictionary/61809/2 "2021-05-25T20:11:28Z")

</div>

use `get(B, "3", 0)`. Check out `? get` for the documentation.

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [May 26, 2021, 5:34pm UTC](https://discourse.julialang.org/t/lacking-keys-values-in-a-dictionary/61809/3 "2021-05-26T17:34:08Z")

</div>

Is this what you have in mind:

```julia
julia> A = Dict(["1" => 1, "3" => 3, "5" => 5]);

julia> B = Dict(["1" => 11, "2" => 22, "5" => 55]);

julia> # Sorting. Otherwise the order of entries in `B_new` is indeterminate.
       keyA = sort(collect(keys(A)));

julia> B_new = [get(B, k, 0) for k in keyA]
3-element Vector{Int64}:
 11
  0
 55

```

Or am I making it too complicated?
