# Looking for a key in a nested dict

**URL:** https://discourse.julialang.org/t/looking-for-a-key-in-a-nested-dict/17211
**Category:** New to Julia
**Created:** [November 6, 2018, 11:21am UTC](https://discourse.julialang.org/t/looking-for-a-key-in-a-nested-dict/17211 "2018-11-06T11:21:00Z")
**Posts on this page:** 1
**Showing post:** 9

<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: [November 6, 2018, 2:16pm UTC](https://discourse.julialang.org/t/looking-for-a-key-in-a-nested-dict/17211/9 "2018-11-06T14:16:50Z")

</div>

If it ocurs multiple times, only the first appearance of the key is returned. Here is an implementation that takes into account multiple returns

```julia
function retrieve(dict, key_of_interest, output = []) # default value is an empty array
               for (key, value) in dict
               if key == key_of_interest
                       push!(output, value)
               end
               if value isa AbstractDict
                   retrieve(value, key_of_interest, output)
               end
           end
           return output
       end

```

---

_[View the full topic](https://discourse.julialang.org/t/looking-for-a-key-in-a-nested-dict/17211)._
