1

我有 2 个数组。例如

x= [1,2,3,4,5]
y= [a,b,c,d,e]

如何合并它们,以便我有一个如下所示的数组

z=[[1,a],[2,b],[3,c],[4,d],[5,e]]
4

2 回答 2

6

简短的回答是......

x.zip y
于 2012-07-16T06:55:49.980 回答
0
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"]] 
于 2012-07-16T07:04:12.090 回答