Beginners mistake - both classes get copy of the same class variable
Even worth - 10 * [10 * [0]] - in Python, you usually put list on the left! - creates list of 10 references to innermost list
SuperGrid.new
, instead of new lists created per class.Even worth - 10 * [10 * [0]] - in Python, you usually put list on the left! - creates list of 10 references to innermost list
def __init__(self, square_size): self.square = [[0] * square_size for _ in range (square_size)]will produce 10 individual lists of 10 individual sub-lists for each class - given that
square_size
is 10
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.