From: Meino Christian Cramer Date: 2006-03-31T14:54:42+09:00 Subject: Re: Most simple way to do "array + array => hash" From: Hal Fulton Subject: Re: Most simple way to do "array + array => hash" Date: Fri, 31 Mar 2006 14:39:58 +0900 Hi Hal, no, it seems not (from my irb): >> a=("A".."Z").to_a => ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"] >> b=("A".."Z").sort_by{rand} => ["D", "C", "X", "P", "Y", "R", "S", "W", "N", "L", "U", "A", "Z", "B", "M", "T", "O", "K", "Q", "G", "I", "F", "J", "H", "V", "E"] >> c=Hash[*a.zip(b)] => {["E", "Y"]=>["F", "R"], ["Q", "O"]=>["R", "K"], ["A", "D"]=>["B", "C"], ["W", "J"]=>["X", "H"], ["M", "Z"]=>["N", "B"], ["U", "I"]=>["V", "F"], ["C", "X"]=>["D", "P"], ["I", "N"]=>["J", "L"], ["O", "M"]=>["P", "T"], ["G", "S"]=>["H", "W"], ["Y", "V"]=>["Z", "E"], ["S", "Q"]=>["T", "G"], ["K", "U"]=>["L", "A"]} by the way: Is there a howto, a piece of text or a webpage or... which describes all these "nice little things" which are possible in ruby in a single line of code and which occupy the half of a page of cryptic code in other languages ? Especially ruby newbies like me often fall over such "little things" like converting a "A" to a 65, cause doing "A"[0] is very simple but not what a long year C-coder would exspect at first hand. Ruby! mcc > Meino Christian Cramer wrote: > > Hi, > > > > Is there a ruby-like way to make an hash from two equeal sized > > arrays, one containing the keys only and the other the values ? > > > > Thanks a lot for any help in advance ! > > > > Would this work? > > Hash[*arr1.zip(arr2)] > > > Hal > >