gpt4 book ai didi

ruby - 计算 Ruby 中的哈希值

转载 作者:数据小太阳 更新时间:2023-10-29 06:39:14 27 4
gpt4 key购买 nike

<分区>

我在 Ruby 中有一个散列数组,如下所示:

domains = [
{ "country" => "Germany"},
{"country" => "United Kingdom"},
{"country" => "Hungary"},
{"country" => "United States"},
{"country" => "France"},
{"country" => "Germany"},
{"country" => "Slovakia"},
{"country" => "Hungary"},
{"country" => "United States"},
{"country" => "Norway"},
{"country" => "Germany"},
{"country" => "United Kingdom"},
{"country" => "Hungary"},
{"country" => "United States"},
{"country" => "Norway"}
]

我想从这个哈希数组创建一个新的哈希,看起来像这样:

counted = {
"Germany" => "3",
"United Kingdom" => "United Kingdom",
"Hungary" => "3",
"United States" => "4",
"France" => "1"
}

有使用 Ruby 1.9 的简单方法吗?

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