# Does anyone else find the behavior of \`Dict(::NamedTuple)\` a little funky:\`\`\`juli

**URL:** https://discourse.julialang.org/t/does-anyone-else-find-the-behavior-of-dict-namedtuple-a-little-funky-juli/56050
**Category:** General Usage
**Created:** [February 25, 2021, 9:33pm UTC](https://discourse.julialang.org/t/does-anyone-else-find-the-behavior-of-dict-namedtuple-a-little-funky-juli/56050 "2021-02-25T21:33:33Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)
#### Post date: [February 25, 2021, 9:33pm UTC](https://discourse.julialang.org/t/does-anyone-else-find-the-behavior-of-dict-namedtuple-a-little-funky-juli/56050/1 "2021-02-25T21:33:33Z")

</div>

does anyone else find the behavior of `Dict(::NamedTuple)` a little funky:

```julia
julia&gt; kw = (default_u0 = [0., 0., 0.], default_p=[0., 0., 0.])
(default_u0 = [0.0, 0.0, 0.0], default_p = [0.0, 0.0, 0.0])

julia&gt; kwd = Dict(kw)
Dict{Float64, Float64} with 1 entry:
  0.0 =&gt; 0.0

```

doesn’t it make way more sense to do `Dict(keys(kw) .=&gt; values(kw))`?

Note that the original poster on Slack cannot see your response here on Discourse. Consider _transcribing the appropriate answer back to Slack_, or pinging the poster here on Discourse so they can _follow this thread_.  
[(Original message :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1614288667422200?thread_ts=1614288667.422200&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

### Author: ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)
#### Post date: [February 27, 2021, 10:08am UTC](https://discourse.julialang.org/t/does-anyone-else-find-the-behavior-of-dict-namedtuple-a-little-funky-juli/56050/2 "2021-02-27T10:08:17Z")

</div>

> [@BridgeBot](#):
>
> `kw = (default_u0 = [0., 0., 0.], default_p=[0., 0., 0.])`

I think you’re looking for `Dict(pairs(kw))`. Here’s the explanation: `Dict` expects an iterable of `key, value` pairs, but it’s not picky about whether it’s an actual `Pair`. This demo may explain it:

```julia
julia> t = (a = [1, 2, 3], b = [4, 5, 6])
(a = [1, 2, 3], b = [4, 5, 6])

julia> for item in t # iteration over tuples (named or not) returns the *values*
           @show item
       end
item = [1, 2, 3]
item = [4, 5, 6]

julia> Dict(t) # the Dict constructor accepts any iterable that returns items supporting `item[1], item[2]`
Dict{Int64, Int64} with 2 entries:
  4 => 5
  1 => 2

julia> for item in pairs(t) # this iterates over key=>value pairs
           @show item
       end
item = :a => [1, 2, 3]
item = :b => [4, 5, 6]

julia> Dict(pairs(t))
Dict{Symbol, Vector{Int64}} with 2 entries:
  :a => [1, 2, 3]
  :b => [4, 5, 6]

```

However, I agree that there is room for confusion here. I’ve filed an issue to consider this topic when we get a chance to consider breaking changes: [Less quacking in Dict constructor? · Issue #39848 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/39848)
