From: sto.mar@... Date: 2013-07-11T23:04:42+09:00 Subject: Re: create variables depending on counter Am 11.07.2013 09:34, schrieb stefan heinrich: > my code to read out the tablewidget and create the array. > > array = Array.new > > for i in 0..rowCount - 1 > tmp = Array.new > tmp << @tableWidget.item(i, 1).text.to_a > tmp << @tableWidget.item(i, 0).text.to_a > tmp = tmp[0] + tmp[1] > > array << tmp > end > > array.group_by {|s,i| s} > array= array.group_by {|s,i| s}.each {|k,v| v.map! {|s,i| i}} > > The 2d array looks like this after grouping > > {"I OFF"=>["a8", "1e"], "E OFF"=>["98", "a0"], "Emphasized ON"=>["db"], > "I ON"=>["99"]} > > It seems like after using grouping by it is not an array anymore. Yes indeed, as mentioned several times in the previous posts, we are talking about a **Hash** of key-value pairs (where the values in this case are arrays). And I already demonstrated in my examples how you can access the stored arrays separately. A reminder: data = {"I OFF"=>["a8", "1e"], "E OFF"=>["98", "a0"], "Emphasized ON"=>["db"], "I ON"=>["99"]} p data['I OFF'] # => ["a8", "1e"] Also, I would like to repeat myself: > I suggest you also look into the docs for the Hash class and > make heavy use of irb. And: Try to figure out what happens in the code examples that people provide here. Regards, Marcus --