Nat*_*lin 4 syntax dictionary initialization vector julia
我试图做的时候:
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中初始化字典?
Tas*_*nou 14
该{}
语法已在julia中弃用了一段时间了.现在构建字典的方法是:
给定一个可迭代的参数,构造一个Dict,其键值对取自参数生成的2元组(键,值).
Run Code Online (Sandbox Code Playgroud)julia> Dict([("A", 1), ("B", 2)]) Dict{String,Int64} with 2 entries: "B" => 2 "A" => 1
或者,可以传递一对参数.
Run Code Online (Sandbox Code Playgroud)julia> Dict("A"=>1, "B"=>2) Dict{String,Int64} with 2 entries: "B" => 2 "A" => 1
(从文档中引用,可以通过?
在终端中按下来访问"帮助"模式,然后键入Dict
)