From: Alex Gutteridge Date: 2011-02-07T20:59:37+09:00 Subject: Re: making hash key from arrays On Mon, 7 Feb 2011 20:47:45 +0900, Arihan Sinha wrote: > Hi All, > > I've two arrays, > > keys = [300,300,301,301,301,302,302] > > values = [1, 2, 1, 3, 4, 3, 4] > > both the arrays have equal size. > > I need to create a hask > > hsh = {"300" =>["1","2"],"301" => ["1","3","4"],"302"=>["3","4"]} > > Could any one please put the ruby code for this. > > > Cheers > A hsh = Hash.new{|h,k| h[k]=[]} keys.zip(values).each{|k,v| hsh[k] << v} -- Alex Gutteridge