# Issue while using dictionary in Julia

**URL:** <https://discourse.julialang.org/t/issue-while-using-dictionary-in-julia/64925>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 19, 2021, 2:07pm UTC](https://discourse.julialang.org/t/issue-while-using-dictionary-in-julia/64925 "2021-07-19T14:07:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![manoj.centura](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manoj.centura/32/216443_2.png) [@manoj.centura](https://discourse.julialang.org/u/manoj.centura)\
**Post date:** [July 19, 2021, 2:07pm UTC](https://discourse.julialang.org/t/issue-while-using-dictionary-in-julia/64925/1 "2021-07-19T14:07:12Z")

</div>

```julia
items = Dict{String,Int64}
Total_craneMovement =985
MaxCraneMovement =312
 CraneIntensity =Total_craneMovement/MaxCraneMovement
push!(items,"Total_craneMovement"=>Total_craneMovement)
push!(items,"MaxCraneMovement"=>MaxCraneMovement)
push!(items,"CraneIntensity"=>CraneIntensity)

```

MethodError: no method matching push!(::Type{Dict{String, Float64}}, ::Pair{String, Int64})  
Closest candidates are:  
push!(::Any, ::Any, !Matched::Any) at abstractarray.jl:2387  
push!(::Any, ::Any, !Matched::Any, !Matched::Any…) at abstractarray.jl:2388  
push!(!Matched::CategoricalArrays.CategoricalVector{T, R, V, C, U} where {T, R\<:Integer, V, C, U}, ::Any) at C:\Users\manojkumar.ram.julia\packages\CategoricalArrays\rDwMt\src\array.jl:866  
…  
in eval at base\boot.jl:360  
in top-level scope at untitled:5

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [July 19, 2021, 2:26pm UTC](https://discourse.julialang.org/t/issue-while-using-dictionary-in-julia/64925/2 "2021-07-19T14:26:29Z")

</div>

> [@manoj.centura](#):
>
> `items = Dict{String,Int64}`

This line makes `items` equal to the _type_ `Dict{String, Int64}`; it doesn’t actually create a dictionary. You want `Dict{String, Int64}()` to actually construct a new `Dict`.

---

<div class="post-metadata">

**Author:** ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)\
**Post date:** [July 19, 2021, 3:19pm UTC](https://discourse.julialang.org/t/issue-while-using-dictionary-in-julia/64925/3 "2021-07-19T15:19:10Z")

</div>

This mistake is so common, that it probably deserve it’s own error message. Something like

```julia
push!(::Type{Dict}, whatever...) = error("You are trying to push in a type, maybe you wanted to instantiate your variable with Dict()? Pay special attention to brackets after Dict.")

```

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [July 19, 2021, 6:08pm UTC](https://discourse.julialang.org/t/issue-while-using-dictionary-in-julia/64925/4 "2021-07-19T18:08:49Z")

</div>

That would be a really good pr (also a good first pr if someone is trying to start contributing).

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [July 20, 2021, 10:57am UTC](https://discourse.julialang.org/t/issue-while-using-dictionary-in-julia/64925/6 "2021-07-20T10:57:22Z")

</div>

Another possible improvement would be to change the metric for “closest candidates” so that replacing a type by its instance counts as very “close”. This would put push!(::AbstractDict, ::Pair)` at the top of the list in the current error message.
