Create two-dimensional arrays and access sub-arrays in Ruby

前端 未结 9 966
走了就别回头了
走了就别回头了 2020-11-28 03:26

I wonder if there\'s a possibility to create a two dimensional array and to quickly access any horizontal or vertical sub array in it?

I believe we can access a hor

9条回答
  •  孤城傲影
    2020-11-28 03:57

    Here is the simple version

     #one
     a = [[0]*10]*10
    
     #two
    row, col = 10, 10
    a = [[0]*row]*col
    

提交回复
热议问题