Nov-13-2019, 12:31 PM
You can use numpy to create your 2D array, or perhaps a bit easier is an array of arrays.
So, assume a 10 by 10 array. Build it by creating a 10 element list, and append that list to your array 10 times creating 10 rows. You then access each row and column as ary[row][col].
Now, you need to avoid a gotcha. When appending each row to your array, you need a copy of that list, otherwise you can end up with 10 references to the same list.
Done this a couple times as early projects, once making the board for Conway's Game of Life and once for making the board for a Sudoku solver.
So, assume a 10 by 10 array. Build it by creating a 10 element list, and append that list to your array 10 times creating 10 rows. You then access each row and column as ary[row][col].
Now, you need to avoid a gotcha. When appending each row to your array, you need a copy of that list, otherwise you can end up with 10 references to the same list.
Done this a couple times as early projects, once making the board for Conway's Game of Life and once for making the board for a Sudoku solver.