我试图做的时候:
d = {1:2, 3:10, 6:300, 2:1, 4:5}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
syntax: { } vector syntax is discontinued
Run Code Online (Sandbox Code Playgroud)
如何在Julia中初始化字典?
在 python 中,你可以像这样迭代字典:
dict1 = {'a':1, 'b':2}
for key, value in dict1.items():
print(key, value)
# -> a 1
# b 2
Run Code Online (Sandbox Code Playgroud)
你如何在朱莉娅身上做同样的事情?
我发现的最接近的是这个,但它并不是最佳的:
D = Dict("a"=>1, "b"=>2)
for a_pair in D
println(a_pair.first, a_pair.second)
end
Run Code Online (Sandbox Code Playgroud)