使用一组数组作为键和值在 julia 中创建字典?

Moh*_*aad 2 dictionary julia

我使用以下代码创建一个使用数组作为键和值的字典。

例如:

k = [1,2,3,4]
v = [2,3,4,5]

for i in 1:length(k)
    get!(d, k[i], v[i])
end

#Output
Dict{Int64,Int64} with 4 entries:
  4 => 5
  2 => 3
  3 => 4
  1 => 2
Run Code Online (Sandbox Code Playgroud)

我可以知道是否有更简单的方法(最好是单行)来实现此操作?

谢谢!

Jun*_*ian 5

julia> Dict(zip(k,v))
Dict{Int64, Int64} with 4 entries:
  4 => 5
  2 => 3
  3 => 4
  1 => 2
Run Code Online (Sandbox Code Playgroud)