我正在使用Julia 1.63并尝试在循环中创建一个字典。
我可以从以下字典开始。
我对此感到疑惑的是,这在字典的上层 工作。
dict = Dict("A_1" => 1, "B_1" => 2, "X" => "A_1" => 1)
Dict{String, Any} with 3 entries:
"X" => "A_1"=>1
"B_1" => 2
"A_1" => 1
现在我想将键“X”添加键值对“B_2” => 2。
我尝试了以下内容:
push!(dict["X"],Dict("B_2" => 2))
ERROR: MethodError: no method matching push!(::Pair{String, Int64}, ::Dict{String, Int64})
Closest candidates are:
push!(::Any, ::Any, ::Any) at abstractarray.jl:2387
push!(::Any, ::Any, ::Any, ::Any...) at abstractarray.jl:2388
push!(::AbstractChannel, ::Any) at channels.jl:10
push!(dict["X"],"B_2" => 2)
ERROR: MethodError: no method matching push!(::Pair{String, Int64}, ::Pair{String, Int64})
Closest candidates are:
push!(::Any, ::Any, ::Any) at abstractarray.jl:2387
push!(::Any, ::Any, ::Any, ::Any...) at abstractarray.jl:2388
push!(::AbstractChannel, ::Any) at channels.jl:10
我对此感到疑惑的是,这在字典的上层 工作。
push!(dict,"B_2" => 2)
Dict{String, Any} with 4 entries:
"B_2" => 2
"X" => "A_1"=>1
"B_1" => 2
"A_1" => 1
我是否忽略了什么显而易见的问题?感谢您的帮助。