Which fix removes the bug?
class Node:
children = []
def add(self, c):
self.children.append(c)
- Create it per instance in
__init__ - Create it per instance in
__new__ - Change
appendtoself.children + [c] - Mark
childrenas a@propertyvalue
A class attribute is shared by every instance, so all nodes get the same children list.
Play Problem Solving ▸