Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私は2つの配列を持っています。例えば
x= [1,2,3,4,5] y= [a,b,c,d,e]
以下のような配列になるようにそれらをマージするにはどうすればよいですか
z=[[1,a],[2,b],[3,c],[4,d],[5,e]]
短い答えは.....
x.zip y
1.9.3p194 :011 > x= [1,2,3,4,5] => [1, 2, 3, 4, 5] 1.9.3p194 :012 > y= ['a','b','c','d','e'] => ["a", "b", "c", "d", "e"] 1.9.3p194 :013 > x.zip(y) => [[1, "a"], [2, "b"], [3, "c"], [4, "d"], [5, "e"]]