gpt4 book ai didi

arrays - ruby array hash get key by value 和 value by key

转载 作者:数据小太阳 更新时间:2023-10-29 07:42:24 25 4
gpt4 key购买 nike

<分区>

我有散列{ "1"=> "one", "2"=> "two", "3"=> "three"}

如何按值取键和按键取值。

如果我通过“1”我得到“一”,如果我通过“二”我得到“2”

def finder (string)
table = { "1" => "one", "2" => "two", "3" => "three" }
*magick*
}
return string
end
puts finder("1") => one
puts finder("one") => 1

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