# Package or Function to find and access keys in a nested dicts

**URL:** <https://discourse.julialang.org/t/package-or-function-to-find-and-access-keys-in-a-nested-dicts/91909>\
**Category:** New to Julia\
**Created:** [December 20, 2022, 5:55pm UTC](https://discourse.julialang.org/t/package-or-function-to-find-and-access-keys-in-a-nested-dicts/91909 "2022-12-20T17:55:22Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![ellocco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ellocco/32/31331_2.png) [@ellocco](https://discourse.julialang.org/u/ellocco)\
**Post date:** [December 20, 2022, 9:58pm UTC](https://discourse.julialang.org/t/package-or-function-to-find-and-access-keys-in-a-nested-dicts/91909/10 "2022-12-20T21:58:10Z")

</div>

Sorry, I saw that there are two versions of the function, [the second version](https://discourse.julialang.org/t/looking-for-a-key-in-a-nested-dict/17211/9)  
works fine.

I have added a check, if only one instance of the `key_of_interrest` is included in the Dict,  
if this is the case the output is a scalar:

```julia
function _retrieve(dict, key_of_interest, output = []) # default value is an empty array
    for (key, value) in dict
        println("key: ", key, ", typeof(key): ", typeof(key))
        if key == key_of_interest
            push!(output, value)
        end
        if value isa AbstractDict
            _retrieve(value, key_of_interest, output)
        end
    end
    if size(output)[1] == 1
        output = output[]
    end
    return output
end

```

---

_[View the full topic](https://discourse.julialang.org/t/package-or-function-to-find-and-access-keys-in-a-nested-dicts/91909)._
