I want to create a 2d array of integer values initially set to 0.
This is how I would think to do it:
grid = [[0] * width] * height
But this just creates each row as a reference to the original, so doing something like
grid[0][1] = 1
will modify all of the grid[n][1] values.
This is my solution:
grid = [[0 for x in range(width)] for y in range(height)]
It feels wrong, is there a better more pythonic way to do this?
EDIT: Bonus question, if the grid size is never going to change and will only contain integers should I use something like a tuple or array.array instead?