# Constructing a Dict but not sure WHY it works

**URL:** <https://discourse.julialang.org/t/constructing-a-dict-but-not-sure-why-it-works/76710>\
**Category:** New to Julia\
**Created:** [February 18, 2022, 4:48pm UTC](https://discourse.julialang.org/t/constructing-a-dict-but-not-sure-why-it-works/76710 "2022-02-18T16:48:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [February 18, 2022, 4:48pm UTC](https://discourse.julialang.org/t/constructing-a-dict-but-not-sure-why-it-works/76710/1 "2022-02-18T16:48:13Z")

</div>

I am using example code to learn julia when I can. I have come across this line

```julia
my_dict = Dict( compt => Dict{ String, Any }() for compt in comp_list) 

```

I can see what it’s doing BUT the area I am uncertain about is

```julia
, Any}()

```

So my question boils down to

“why is the () for Any outside the } of the Dict?”

thank you

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [February 18, 2022, 4:58pm UTC](https://discourse.julialang.org/t/constructing-a-dict-but-not-sure-why-it-works/76710/2 "2022-02-18T16:58:05Z")

</div>

That’s not an `()` for `Any`, that’s just the `()` that instantiates an empty `Dict`:

```julia
julia> Dict{String, Any} # This is just a type, not an object of the type!
Dict{String, Any}

julia> Dict{String, Any}() # Adding the () actually creates an instance of this type
Dict{String, Any}()

julia> Dict(letter => Dict{String, Any}() for letter ∈ 'a':'e') # a dict comprehension creates a dict where the values are other dicts
Dict{Char, Dict{String, Any}} with 5 entries:
  'a' => Dict()
  'c' => Dict()
  'd' => Dict()
  'e' => Dict()
  'b' => Dict()

```

---

<div class="post-metadata">

**Author:** ![anon69491625](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@anon69491625](https://discourse.julialang.org/u/anon69491625)\
**Post date:** [February 18, 2022, 5:08pm UTC](https://discourse.julialang.org/t/constructing-a-dict-but-not-sure-why-it-works/76710/3 "2022-02-18T17:08:19Z")

</div>

Hi @nilshg thank you so much AGAIN!! I am still plugging away here but can only do it spasmodically 🙂 Great explanation as always!

have an EXCELLENT weekend and stay out of storm Eunice 🙂
