How to initialize an array of dicts? Is there any suggested ways to do it?

julia> (Int64=>Int64)[]
Dict{Int64,Int64} with 0 entries

# And since brackets creates Arrays:
julia> Any[]
0-element Array{Any,1}

# So I suppose this would generate array of dicts, until it fails:
julia> ((Int64=>Int64)[])[]
ERROR: `getindex` has no method matching getindex(::Dict{Int64,Int64})




On Sunday, May 4, 2014 5:02:14 AM UTC+8, thom lake wrote:
>
> One thing that I like about {} for initializing Array{Any,1}, is the 
> consistency with comprehension syntax. Namely, braces for Any, brackets for 
> specific types
>
> julia> typeof({i=>2i for i = 1:10})
> Dict{Any,Any}
>
> julia> typeof([i=>2i for i = 1:10])
> Dict{Int64,Int64}
>
> julia> typeof({2i for i = 1:10})
> Array{Any,1}
>
> julia> typeof([2i for i = 1:10])
> Array{Int64,1}
>
>
>

Reply via email to