From: Andrew Timberlake Date: 2009-02-15T21:12:19+09:00 Subject: Re: Multidimensional hash - get all not blank keys --001636c9247950a34d0462f40189 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Sun, Feb 15, 2009 at 1:44 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] > > thanks > michael > -- > Posted via http://www.ruby-forum.com/. > => result.each do |k,v| puts "#{k} = #{v.reject{|k2,v2| v2 == ''}.inspect}" end 1 = {"1"=>"Value1", "3"=>"Value2"} 2 = {"8"=>"Value3"} 3 = {} 4 = {"8"=>"Value4", "2"=>"Value5"} You should be able to take that and massage it into what you need. Andrew Timberlake http://ramblingsonrails.com http://www.linkedin.com/in/andrewtimberlake "I have never let my schooling interfere with my education" - Mark Twain --001636c9247950a34d0462f40189--