William James
2/15/2009 8:44:00 PM
Michael .. wrote:
> Hello.
>
> I have this Hash.
>
> result={"1"=>{"6"=>"",
> "7"=>"",
> "8"=>"",
> "1"=>"Value1",
> "2"=>"",
> "3"=>"Value2",
> "4"=>"",
> "5"=>""},
> "2"=>{"6"=>"",
> "7"=>"",
> "8"=>"Value3",
> "1"=>"",
> "2"=>"",
> "3"=>"",
> "4"=>"",
> "5"=>""},
> "3"=>{"6"=>"",
> "7"=>"",
> "8"=>"",
> "1"=>"",
> "2"=>"",
> "3"=>"",
> "4"=>"",
> "5"=>""},
> "4"=>{"6"=>"",
> "7"=>"",
> "8"=>"Value4",
> "1"=>"",
> "2"=>"Value5",
> "3"=>"",
> "4"=>"",
> "5"=>""}
> }
>
>
> Is it possible to get all keys with a the value.
> 1,[1 => Value1]
> 1,[3 => Value2]
> 2,[8 => Value3]
> 4,[8 => Value4]
> 4,[2 => Value5]
>
result.delete_if{|k,v| {} == v.delete_if{|a,b| b==""}}
p result
{"1"=>{"1"=>"Value1", "3"=>"Value2"}, "2"=>{"8"=>"Value3"},
"4"=>{"8"=>"Value4", "2"=>"Value5"}}