From: gwtmp01@... Date: 2005-12-01T07:24:16+09:00 Subject: Re: Help constructing interesting hash? On Nov 30, 2005, at 4:57 PM, Chris McMahon wrote: > Now suppose I have a AoA like > > [[A, B, C,][1,2,2]] > > Is there a readable way to construct a hash like > > 1=>[A] > 2=>[B, C] input = [[:A, :B, :C],[1,2,2]] output = {} input[1].each_with_index { |group, index| (output[group] ||= []) << input[0][index] } puts "input: #{input.inspect}" puts "output: #{output.inspect}" ---------------- input: [[:A, :B, :C], [1, 2, 2]] output: {1=>[:A], 2=>[:B, :C]}