So, I'm trying to create a nested list in Python based on width and height. This is what I still have:
width = 4 height = 5 row = [None]*width map = [row]*height
Now this is obviously not entirely correct. When printed, it looks fine:
[[None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None], [None, None, None, None]]
But an attempt to assign a value to this position:
map[2][3] = 'foo'
I get:
[[None, None, None, 'foo'], [None, None, None, 'foo'], [None, None, None, 'foo'], [None, None, None, 'foo'], [None, None, None, 'foo']]
It is clear that this is because each sublist really just refers to the same object, row, so it changes one, it changes them all. So this is the closest I have!
How can I dynamically generate a nested list? Thanks!