Why is the matrix filled with namedtuples like this?
Incorrectly inserted indexes
And how to fix it?
from collections import namedtuple
Point = namedtuple('Point', ['x', 'y'])
m, n = 3, 3
matrix = [[None] * n] * m
for i in range(m):
for j in range(n):
matrix[i][j] = Point(i, j)
for row in matrix:
print(row)
#>>Output
#[Point(x=2, y=0), Point(x=2, y=1), Point(x=2, y=2)]
#[Point(x=2, y=0), Point(x=2, y=1), Point(x=2, y=2)]
#[Point(x=2, y=0), Point(x=2, y=1), Point(x=2, y=2)]
The result should be
#>>Output
#[Point(x=0, y=0), Point(x=0, y=1), Point(x=0, y=2)]
#[Point(x=1, y=0), Point(x=1, y=1), Point(x=1, y=2)]
#[Point(x=2, y=0), Point(x=2, y=1), Point(x=2, y=2)]