123, "b" => 456, "c" => 789) 将给出以下数组: ["a", "b", "c"] 最-6ren">
gpt4 book ai didi

arrays - 如何获取字典中所有键的数组?

转载 作者:行者123 更新时间:2023-12-05 00:44:23 25 4
gpt4 key购买 nike

如何在 Julia 中将字典的所有键作为单独的数组获取。

例如:

Dict("a" => 123, "b" => 456, "c" => 789)

将给出以下数组:

["a", "b", "c"]

最佳答案

你可以这样做(如果一个迭代器对你来说足够了,你只需使用 keys 来避免实现数组):

julia> d = Dict("a" => 123, "b" => 456, "c" => 789)
Dict{String, Int64} with 3 entries:
"c" => 789
"b" => 456
"a" => 123

julia> keys(d)
KeySet for a Dict{String, Int64} with 3 entries. Keys:
"c"
"b"
"a"

julia> collect(keys(d))
3-element Vector{String}:
"c"
"b"
"a"

关于arrays - 如何获取字典中所有键的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67110175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com