小编Was*_*rox的帖子

交换红宝石哈希中的密钥

在Ruby中,如何在Hash中交换密钥?

假设我有以下哈希:

{:one=>1, :two=>2, :three=>3, :four=>4 }
Run Code Online (Sandbox Code Playgroud)

我想转变成:

{:one=>1, :three=>2, :two=>3, :four=>4}
Run Code Online (Sandbox Code Playgroud)

也就是说,交换密钥:两个和三个但保持其值不变.

什么是最有效的解决方案?

ruby hash hashmap

2
推荐指数
1
解决办法
815
查看次数

标签 统计

hash ×1

hashmap ×1

ruby ×1