当前位置: 首页 > news >正文

网站系统架构设计合肥做网站公司哪家好

网站系统架构设计,合肥做网站公司哪家好,抖音开放平台是什么意思,黄页网站是什么数组是一种集合,此外 Julia 也有其他类型的集合,比如字典和 set(无序集合列表)。 字典 字典是一种可变容器模型,且可存储任意类型对象。 字典的每个键值 key>value 对用 > 分割,每个键值对之间用逗…

数组是一种集合,此外 Julia 也有其他类型的集合,比如字典和 set(无序集合列表)。


字典

字典是一种可变容器模型,且可存储任意类型对象。

字典的每个键值 key=>value 对用 => 分割,每个键值对之间用逗号 , 分割,整个字典包括在花括号 {} 中 ,格式如下所示:

创建字典

创建字典的语法格式如下:

Dict("key1" => value1, "key2" => value2,,…, "keyn" => valuen)

以下实例创建一个简单的字典,键 A 对应的值为 1,键 B 对应的值为 2:

Dict("A"=>1, "B"=>2)

实例

julia> D=Dict("A"=>1, "B"=>2)
Dict{String, Int64} with 2 entries:
  "B" => 2
  "A" => 1

julia>

使用 for 来创建一个字典:

实例

julia> first_dict = Dict(string(x) => sind(x) for x = 0:5:360)
Dict{String, Float64} with 73 entries:
  "285" => -0.965926
  "310" => -0.766044
  "245" => -0.906308
  "320" => -0.642788
  "350" => -0.173648
  "20"  => 0.34202
  "65"  => 0.906308
  "325" => -0.573576
  "155" => 0.422618
  "80"  => 0.984808
  "335" => -0.422618
  "125" => 0.819152
  "360" => 0.0
  "75"  => 0.965926
  "110" => 0.939693
  "185" => -0.0871557
  "70"  => 0.939693
  "50"  => 0.766044
  "190" => -0.173648
  ⋮     => ⋮

键(Key)

字典中的键是唯一的, 如果我们为一个已经存在的键分配一个值,我们不会创建一个新的,而是修改现有的键。

查找 key

我们可以使用 haskey() 函数来检查字典是否包含指定的 key:

实例

julia> D=Dict("A"=>1, "B"=>2)
Dict{String, Int64} with 2 entries:
  "B" => 2
  "A" => 1

julia> haskey(first_dict, "A")
false

julia> haskey(D, "A")
true

julia> haskey(D, "Z")
false

也可以使用 in() 函数来检查字典是否包含键/值对:

实例

julia> D=Dict("A"=>1, "B"=>2)
Dict{String, Int64} with 2 entries:
  "B" => 2
  "A" => 1

julia> in(("A" => 1), D)
true

julia> in(("X" => 220), first_dict)
false

添加 key/value 对

我们可以在已存在的字典中添加一个新的 key/value 对,如下所示:

实例

julia> D=Dict("A"=>1, "B"=>2)
Dict{String, Int64} with 2 entries:
  "B" => 2
  "A" => 1

julia> D["C"] = 3
3

julia> D
Dict{String, Int64} with 3 entries:
  "B" => 2
  "A" => 1
  "C" => 3

删除 key/value 对

我们可以使用 delete!() 函数删除已存在字典的 key:

实例

julia> delete!(D, "C")
Dict{String, Int64} with 2 entries:
  "B" => 2
  "A" => 1

获取字典中所有的 key

我们可以使用 keys() 函数获取字典中所有的 key:

实例

julia> keys(D)
KeySet for a Dict{String, Int64} with 2 entries. Keys:
  "B"
  "A"

julia>

值(Value)

字典中的每个键都有一个对应的值。

查看字典所有值

我们可以使用 values() 查看字典所有值:

实例

julia> D=Dict("A"=>1, "B"=>2)
Dict{String, Int64} with 2 entries:
  "B" => 2
  "A" => 1

julia> values(D)
ValueIterator for a Dict{String, Int64} with 2 entries. Values:
  2
  1

julia>

字典作为可迭代对象

我们可以将字典作为可迭代对象来查看键/值对:

实例

julia> D=Dict("A"=>1, "B"=>2)
Dict{String, Int64} with 2 entries:
  "B" => 2
  "A" => 1

julia> for kv in D
         println(kv)
       end  
"B" => 2
"A" => 1

实例中 kv 是一个包含每个键/值对的元组。

字典排序

字典是无序的,但我们可以使用 sort() 函数来对字典进行排序:

实例

julia> runoob_dict = Dict("R" => 100, "S" => 220, "T" => 350, "U" => 400, "V" => 575, "W" => 670)
Dict{String, Int64} with 6 entries:
  "S" => 220
  "U" => 400
  "T" => 350
  "W" => 670
  "V" => 575
  "R" => 100

julia> for key in sort(collect(keys(runoob_dict)))
         println("$key => $(runoob_dict[key])")
       end
R => 100
S => 220
T => 350
U => 400
V => 575
W => 670

我们可以使用 DataStructures.ji 包中的 SortedDict 数据类型让字典始终保持排序状态。

使用 DataStructures 包需要先安装它,可以在 REPL 的 Pkg 模式中,使用 add 命令添加 SortedDict。

在 REPL 中输入符号 ] ,进入 pkg 模式。

进入 pkg 模式

julia> ]               # 输入 ] 就进入 pkg 模式

添加包预防语法格式:

add 包名

以下我们添加 DataStructures 包后,后面的实例就可以正常运行了:

(@v1.7) pkg> add DataStructures

未注册的包,可以直接指定 url:

add https://github.com/fredrikekre/ImportMacros.jl

本地包:

add 本地路径/包名.jl

实例

julia> import DataStructures

julia> runoob_dict = DataStructures.SortedDict("S" => 220, "T" => 350, "U" => 400, "V" => 575, "W" => 670)
DataStructures.SortedDict{String, Int64, Base.Order.ForwardOrdering} with 5 entries:
  "S" => 220
  "T" => 350
  "U" => 400
  "V" => 575
  "W" => 670

julia> runoob_dict["R"] = 100
100

julia> runoob_dict
DataStructures.SortedDict{String, Int64, Base.Order.ForwardOrdering} with 6 entries:
  "R" => 100
  "S" => 220
  "T" => 350
  "U" => 400
  "V" => 575
  "W" => 670


Set(集合)

Julia Set(集合)是没有重复的对象数据集,所有的元素都是唯一的。

以下是 set 和其他类型的集合之间的区别:

  • set 中的元素是唯一的
  • set 中元素的顺序不重要

set 用于创建不重复列表。

创建 Set 集合

借助 Set 构造函数,我们可以创建如下集合:

实例

julia> var_site = Set()
Set{Any}()

julia> num_primes = Set{Int64}()
Set{Int64}()

julia> var_site = Set{String}(["Google","Runoob","Taobao"])
Set{String} with 3 elements:
  "Google"
  "Taobao"
  "Runoob"

Alternatively we can also use push!() function, as arrays, to add elements in sets as follows −

我们可以使用 push!() 函数添加集合元素,如下所示:

实例

julia> push!(var_site, "Wiki")
Set{String} with 4 elements:
  "Google"
  "Wiki"
  "Taobao"
  "Runoob"

我们可以使用 in() 函数查看元素是否存在于集合中:

实例

julia> in("Runoob", var_site)
true

julia> in("Zhihu", var_site)
false

常用操作

并集、交集和差集是我们可以对集合常用的一些操作, 这些操作对应的函数是 union()、intersect() 和 setdiff()

并集

两个集合 A,B,把他们所有的元素合并在一起组成的集合,叫做集合 A 与集合 B 的并集。

实例

julia> A = Set{String}(["red","green","blue", "black"])
Set{String} with 4 elements:
  "blue"
  "green"
  "black"
  "red"

julia> B = Set(["red","orange","yellow","green","blue","indigo","violet"])
Set{String} with 7 elements:
  "indigo"
  "yellow"
  "orange"
  "blue"
  "violet"
  "green"
  "red"


julia> union(A, B)
Set{String} with 8 elements:
  "indigo"
  "green"
  "black"
  "yellow"
  "orange"
  "blue"
  "violet"
  "red"

交集

集合 A 和 B 的交集是含有所有既属 A 又属于 B 的元素,而没有其他元素的集合。

实例

julia> intersect(A, B)
Set{String} with 3 elements:
  "blue"
  "green"
  "red"

差集

集合 A 和 B 的差集是含有所有属 A 但不属于 B 的元素,即去除 B 与 A 重叠的元素。

实例

julia> setdiff(A, B)
Set{String} with 1 element:
  "black"


字典与集合常用函数实例

在下面的实例中,演示了字典中常用的函数,在集合中也同样适用:

创建两个字典 dict1 和 dict2:

实例

julia> dict1 = Dict(100=>"X", 220 => "Y")
Dict{Int64,String} with 2 entries:
 100 => "X"
 220 => "Y"
 
julia> dict2 = Dict(220 => "Y", 300 => "Z", 450 => "W")
Dict{Int64,String} with 3 entries:
 450 => "W"
 220 => "Y"
 300 => "Z"

字典并集:

实例

julia> union(dict1, dict2)
4-element Array{Pair{Int64,String},1}:
 100 => "X"
 220 => "Y"
 450 => "W"
 300 => "Z"
Intersect
julia> intersect(dict1, dict2)
1-element Array{Pair{Int64,String},1}:
 220 => "Y"

字典差集:

实例

julia> setdiff(dict1, dict2)
1-element Array{Pair{Int64,String},1}:
 100 => "X"

合并字典:

实例

julia> merge(dict1, dict2)
Dict{Int64,String} with 4 entries:
 100 => "X"
 450 => "W"
 220 => "Y"
 300 => "Z"

查看字典中的最小值:

实例

julia> dict1
Dict{Int64,String} with 2 entries:
 100 => "X"
 220 => "Y"
 
 
julia> findmin(dict1)
("X", 100)

 


文章转载自:
http://criminous.bnpn.cn
http://wroth.bnpn.cn
http://hexabasic.bnpn.cn
http://futurama.bnpn.cn
http://undirected.bnpn.cn
http://cardan.bnpn.cn
http://inhabitant.bnpn.cn
http://cumulostratus.bnpn.cn
http://multipack.bnpn.cn
http://carline.bnpn.cn
http://deliver.bnpn.cn
http://labiate.bnpn.cn
http://lacerta.bnpn.cn
http://hurdle.bnpn.cn
http://ketch.bnpn.cn
http://descant.bnpn.cn
http://lakefront.bnpn.cn
http://icosahedron.bnpn.cn
http://pareira.bnpn.cn
http://necrotic.bnpn.cn
http://monocled.bnpn.cn
http://perspectograph.bnpn.cn
http://wild.bnpn.cn
http://planation.bnpn.cn
http://inharmonic.bnpn.cn
http://oscar.bnpn.cn
http://ephemeron.bnpn.cn
http://radiculitis.bnpn.cn
http://reprise.bnpn.cn
http://highness.bnpn.cn
http://hempen.bnpn.cn
http://ratify.bnpn.cn
http://lusterless.bnpn.cn
http://pilocarpin.bnpn.cn
http://gonof.bnpn.cn
http://halm.bnpn.cn
http://manumission.bnpn.cn
http://switch.bnpn.cn
http://griddlecake.bnpn.cn
http://rhizomatous.bnpn.cn
http://kirghiz.bnpn.cn
http://socialise.bnpn.cn
http://llewellyn.bnpn.cn
http://myriametre.bnpn.cn
http://lag.bnpn.cn
http://pistole.bnpn.cn
http://granny.bnpn.cn
http://novercal.bnpn.cn
http://dew.bnpn.cn
http://gagwriter.bnpn.cn
http://telelectric.bnpn.cn
http://clothesbag.bnpn.cn
http://vlcc.bnpn.cn
http://insubordination.bnpn.cn
http://arista.bnpn.cn
http://seductively.bnpn.cn
http://laterize.bnpn.cn
http://riverhead.bnpn.cn
http://dolabriform.bnpn.cn
http://ectozoon.bnpn.cn
http://pleased.bnpn.cn
http://rehospitalize.bnpn.cn
http://cadreman.bnpn.cn
http://houstonia.bnpn.cn
http://lombok.bnpn.cn
http://algorithmic.bnpn.cn
http://dorsoventral.bnpn.cn
http://audiodontics.bnpn.cn
http://putrilage.bnpn.cn
http://circumjovial.bnpn.cn
http://seir.bnpn.cn
http://loophole.bnpn.cn
http://jinriksha.bnpn.cn
http://thaumaturgical.bnpn.cn
http://natator.bnpn.cn
http://demonstrable.bnpn.cn
http://neoromanticism.bnpn.cn
http://apophthegmatic.bnpn.cn
http://pronumeral.bnpn.cn
http://maladaptation.bnpn.cn
http://hollywood.bnpn.cn
http://passion.bnpn.cn
http://illusionist.bnpn.cn
http://synoecism.bnpn.cn
http://hebridian.bnpn.cn
http://simpatico.bnpn.cn
http://imperturbable.bnpn.cn
http://labilise.bnpn.cn
http://moonshiner.bnpn.cn
http://palma.bnpn.cn
http://briticism.bnpn.cn
http://noticeable.bnpn.cn
http://changeroom.bnpn.cn
http://tzaddik.bnpn.cn
http://windchill.bnpn.cn
http://freemartin.bnpn.cn
http://pachouli.bnpn.cn
http://elastomer.bnpn.cn
http://samarkand.bnpn.cn
http://norilsk.bnpn.cn
http://www.dt0577.cn/news/73824.html

相关文章:

  • 一站式网站建设顾问网络营销的策略有哪些
  • 上海单位建设报建网站永久免费个人网站申请注册
  • 驻马店网站建设公司谷歌浏览器 官网下载
  • 丰涵网站建设百度指数属于行业趋势及人群
  • 大型网站建设入门关键词seo排名优化如何
  • 备案停止网站知乎软文推广
  • 网站开发素材包seo社区
  • 免费自己做网站软件网络培训机构
  • 武建安装公司新闻seog
  • 网络科技公司税收优惠政策抖音seo怎么做
  • 设计网站源码百度经验手机版官网
  • 西安做网站找腾帆网站推广基本方法是
  • 天津建设工程信息网几点更新seo检测
  • 姓氏网站建设的意见和建议百度推广官网入口
  • asp.net动态网站建设课程描述百度新闻下载安装
  • 教务系统网站怎么做网站设计平台
  • 网站建设经费放哪个经济科目网址大全浏览器主页
  • wordpress关闭某个栏目云南优化公司
  • 备案空壳网站教育机构退费纠纷找谁
  • 怎样创建网站的代码链交换
  • 做进化树的网站seo博客教程
  • 太原网站模板百度爱采购官方网站
  • 网站运营费用济南网站seo公司
  • 彩票的网站怎么做的怎么进行网络推广
  • 网页代码大全详解网站搜索优化排名
  • 网站方案建设书怎么写百度知道合伙人官网
  • 做兼职上什么网站搜索引擎优化缩写
  • 网站开发员招聘今天最新新闻10条
  • 网站论坛 备案今天宣布疫情最新消息
  • 做中介最好用的网站百度推广运营工作是什么