From: Sean O'Halpin Date: 2005-12-01T07:44:51+09:00 Subject: Re: Help constructing interesting hash? On 11/30/05, Chris McMahon wrote: > Suppose I have an array of arrays like > > [[A, B, C][1,2,3]] > > I can easily make a hash (using each_with_index) where one value is > the lookup value for the other value: > > 1=>A > 2=>B > 3=>C > > 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] > > ? > > Thanks, > -Chris > Here's another way: a = [['A', 'B', 'C'],[1,2,3]] h = Hash[*a[0].zip(a[1]).flatten] p h -- OUTPUT -- {"A"=>1, "B"=>2, "C"=>3} Regards, Sean