0

desired and actual outputs

I want to get the first output but initialise the list in the second manner. How can I achieve this? If you can't see the image, I initialise a 2-D list like this:- mat = [[0] * 2] * 2, but when I proceed to set mat[0][1] = 2, each row's second element gets set to 2. I vaguely understand why this happens, but would like to get a solution.

Mappy
  • 5
  • 3

0 Answers0