Is there a way I can identity Dict just like identity Vector?

I often identity Vector:

vec_a=Any[1,2,3]
3-element Vector{Any}:
 1
 2
 3

identity.(vec_a)
3-element Vector{Int64}:
 1
 2
 3

But when I have a Dict:

dict_a=Dict{S,Any}(:a=>1,:b=>2)
Dict{Symbol, Any} with 2 entries:
  :a => 1
  :b => 2

How can I get this?

Dict{Symbol, Int64} with 2 entries:
  :a => 1
  :b => 2

You could do

julia> Dict(keys(dict_a) .=> values(dict_a))
Dict{Symbol, Int64} with 2 entries:
  :a => 1
  :b => 2
3 Likes

Yes, it is just as convinient as “identity”. Thanks so much.

It does create some extra allocations, though. You could try

Dict(key=>val for (key, val) in dict_a) 
3 Likes