How does one make a 2D grid with lists? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How does one make a 2D grid with lists?

15th Mar 2017, 12:00 PM
Patrick
Patrick - avatar
3 Answers
+ 1
Hi, I think lists inside a list is you answer. matrix = [[1,2,3],[4,5,6],[7,8,9]] in this case, matrix has 3 itens (the rows of the grid) matrix[0] = [1,2,3] matrix[1] = [4,5,6] matrix[2] = [7,8,9] and the columns of the grid are the items inside each list. In this case, there are 3 columns. matrix[0][0] = 1 matrix[0][1] = 2 matrix[0][2] =3 so matrix[x][y] x = rows y = columns
17th Mar 2017, 9:04 PM
Rodrigo Caetano
Rodrigo Caetano - avatar
0
Thanks for the answer! A follow-up question, though: Does this mean that the grid made contains only the rows, grids and points you've specified? or are there other points between (and around) these? If not, is there a way to make such a grid? like a Cartesian plane. I'm asking this because I'm trying to write some code to figure out where to place a bunch of rectangles on a single plane such that all their centers are as close to one another as possible, without having them overlapping one another. Would the grid help me out with this? or maybe I should go in another direction? What would you suggest?
20th Mar 2017, 9:09 AM
Patrick
Patrick - avatar
0
Patrick, I just know the very basic python. I do not know if I can help you, but lists will only contain the specific points and I do not know how to plot them, sou you could see the rectangles in the 2d plain.
20th Mar 2017, 7:18 PM
Rodrigo Caetano
Rodrigo Caetano - avatar