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"]]