In python, a matrix can be represented as a list of lists, for example, we have the matriz = [[],[],[]]
, it contains three lists, these lists indicate the rows in the matrix, and the values contained within each of these lists would indicate a column in the matrix, for this list of lists, matriz = [[1,2,3],['a','b','c'],[5,6,7]]
the matrix would look like this:
1 2 3
a b c
5 6 7
the first row would be the first list, the second row would be the second list and so on, for the columns the same, the first column would be all the elements in the first position of all the lists, the second column all the elements of the second position in all the lists and so on, to create a square matrix, the number of items in the lists must be equal, and therefore equal to the size of the containing list, in this case matriz
a more practical example:
matriz = []
for fila in range(4):
fila_nueva=[]
for columna in range(4):
fila_nueva.append(str("celda"+str(fila+1,columna+1))))
matriz.append(fila_nueva)
with this should be something like this
celda 1,1 celda 1,2 celda 1,3 celda 1,4
celda 2,1 celda 2,2 celda 2,3 celda 2,4
celda 3,1 celda 3,2 celda 3,3 celda 3,4
celda 4,4 celda 4,2 celda 4,3 celda 4,4
so to access an element you must first call in which row to search and then in which posisicon of that list, for example to remove the element that is in cell 3, 3, would be elemento = matriz[2][2]