-3

Here is my code

{"wow"=>["wow"], "you"=>["you", "you"], "are"=>["are"], "a"=>["a"], "good"=>["good"], "guy"=>["guy"], "but"=>["but"], "sometime"=>["sometime"], "take"=>["take"], "very"=>["very"], "wrong"=>["wrong"], "decision"=>["decision"]}

i want to get result

{"you"=>2, "are"=>1, "a"=>1, "good"=>1, "guy"=>1, "but"=>1, "sometime"=>1, "take"=>1, "very"=>1, "wrong"=>1, "decision"=>1,"wow" =>1}

how can i do this please help me

4

1 に答える 1

3

試す

old_hash = {"wow"=>["wow"], "you"=>["you", "you"], "are"=>["are"], "a"=>["a"], "good"=>["good"], "guy"=>["guy"], "but"=>["but"], "sometime"=>["sometime"], "take"=>["take"], "very"=>["very"], "wrong"=>["wrong"], "decision"=>["decision"]}

new_hash = Hash.new
old_hash.each {|k,v| new_hash.merge!(k=>v.size) }
于 2013-03-19T05:19:51.763 に答える