0

I have a matrix

matrix = [[0.0] * 4] * 4

it looks like:

0    0    0   0
0    0    0   0
0    0    0   0
0    0    0   0

I'm trying to add an element to the second row, third column so that the matrix looks like this:

0    0    0   0
0    0    3   0
0    0    0   0
0    0    0   0

When I do

matrix[1][2] = 3

it gives:

0    0    3   0
0    0    3   0
0    0    3   0
0    0    3   0

How do I fix this?

cooldood3490
  • 2,418
  • 7
  • 51
  • 66
  • ... and [this](http://stackoverflow.com/q/12791501/198633) – inspectorG4dget Oct 10 '14 at 22:22
  • There are literally hundreds of dups of this question (in fact, this is the third one today!), so I'm not sure how well the particular one I chose answers your question. If it's not clear, follow the Linked and Related questions from there until you find one that does. – abarnert Oct 10 '14 at 22:22
  • Also, this is covered [in the official Python FAQ](https://docs.python.org/3/faq/programming.html#how-do-i-create-a-multidimensional-list). – abarnert Oct 10 '14 at 22:23
  • @abarnert thanks, the one in the official Python FAQ answered my question. – cooldood3490 Oct 10 '14 at 22:29

0 Answers0