On Mon, Feb 7, 2011 at 7:47 PM, Arihan Sinha <arihan_sinha / yahoo.com> wrote:

> keys = [300,300,301,301,301,302,302]
> values = [1, 2, , , , , 4]
> hsh = {"300" =>["1","2"],"301" => ["1","3","4"],"302"=>["3","4"]}

just joining the fun here..  an inject version

keys.zip(values).inject(Hash.new{|h,k|h[k]=[]}) {|hsh,(k,v)|
hsh.tap{|h|h[k] << v}}
#=> {300=>[1, 2], 301=>[1, 3, 4], 302=>[3, 4]}

or

keys.zip(values).inject2(Hash.new{|h,k|h[k]=[]}) {|h,(k,v)| h[k] << v}
#=> {300=>[1, 2], 301=>[1, 3, 4], 302=>[3, 4]}

best regards -botp