Doubt with matrix in Python

Asked

Viewed 59 times

1

I have the following code:

matrix = [[0 for x in range(2)] for y in range(10)]

I’m trying to implement this in another language, in which there is no such structure above for matrix creation.

I wonder if there is another way to write this code in Python, or generic way, in C.

1 answer

1


The python structure you showed dismembered would be something like this:

matrix = []
aux = []

for i in range(10):
    for j in range(2):
        aux.append(0)
    matrix.append(aux)
    aux = []
print(matrix)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.