I tried submitting this code multiple times but was unsuccessful in doing so because of the NZEC.
Please HELP in finding the error.
Firstly, the correct way to initialize 2d arrays in python is:
a = [[0 for _ in range(c)] for _ in range(r)].
When you do
a = [*r]*c, only the first row is created and the pointer/reference to this row is copied to the rest of the rows.
>>> r, c = 3, 3 >>> a = [*r]*c >>> a [[0, 0, 0], [0, 0, 0], [0, 0, 0]] >>> a = 1 >>> a [[1, 0, 0], [1, 0, 0], [1, 0, 0]]
The last result might seem counter-intuitive but when you think about, it makes sense!
Second, the actual bug in your code was that you initialized
a to have c rows and r columns instead of the other way round
Thanks a lot, eragon987!