Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Create List of Lists Grid With Empty Values

WARNING: Need to test this, it might be making copies of the same array which would be bad. Or, at least unexpected.

These work for creating lists of lists in a grid that you can access:

Code

grid = []

grid_size = 4

for i in range(0, grid_size):
	grid.append([None] * grid_size)

print(grid)

Code

grid = []

grid_size = 4

for i in range(0, grid_size):
	grid.append([{"key": "value"}] * grid_size)

print(grid)

Code

[
    [{'key': 'value'}, 
    {'key': 'value'}, 
    {'key': 'value'}, 
    {'key': 'value'}], 
    [{'key': 'value'}, 
    {'key': 'value'}, 
    {'key': 'value'}, 
    {'key': 'value'}], 
    [{'key': 'value'}, 
    {'key': 'value'}, 
    {'key': 'value'}, 
    {'key': 'value'}], 
    [{'key': 'value'}, 
    {'key': 'value'}, 
    {'key': 'value'}, 
    {'key': 'value'}]
]