新手问题 怎样交换 hash 里边儿的 key 和 value

easonlovejiven · January 20, 2015 · Last by pynix replied at January 21, 2015 · 2276 hits

怎样交换 hash 里边儿的 key 和 value

稍微 google 一下就能找到答案 http://stackoverflow.com/questions/10989259/swapping-keys-and-values-in-a-hash

{a: 1, b: 2, c: 3}.invert
=> {1=>:a, 2=>:b, 3=>:c}

下次请楼主先自行 google 一下。

#2 楼 @easonlovejiven 另外看了你近期的一些帖子,很难怀疑你是不是一个伸手党,RubyChina 倒是不排斥新手,不过你的很多问题其实只要稍微 google 一下会比到这里问答案要快很多。

#3 楼 @lgn21st 感谢你的提醒,也感谢你这几次与我的互动,非常感谢!!!经常这样去问别人,也可能是大学留下的后遗症吧,不过我会慢慢适应的。我也是想听取一些有经验的人是怎样去解决此类问题的。。。虽然方式不太合适,我会尽量改掉这个毛病!!!

#3 楼 @lgn21st 伸手党。。。。

You need to Sign in before reply, if you don't have an account, please Sign up first.