Challenge 3: Fix the Shared-List Bug — Possible Solution ==================================================================== class Dog: def __init__(self, name): self.name = name self.tricks = [] # instance attribute now, not a class attribute def add_trick(self, trick): self.tricks.append(trick) rex = Dog("Rex") fido = Dog("Fido") rex.add_trick("sit") print(fido.tricks) # [] — Fido is unaffected WHY THIS WORKS AS AN ANSWER ------------------------------ The buggy version's problem, per the chapter's warn-box, is that tricks = [] sits in the CLASS body, making it one single list object shared by every Dog instance — appending to it through any one dog mutates the same list every other dog also sees. The fix moves self.tricks = [] into __init__, turning it into an INSTANCE attribute instead — the exact instance-vs-class distinction this chapter opened with. Because __init__ runs separately for every new Dog object, each call creates its OWN brand-new empty list, the same "create a fresh instance's own copy inside __init__" principle this chapter's Bank Account challenge also relies on. add_trick still works the same way syntactically (self.tricks.append (trick)), but now self.tricks refers to that one dog's own private list rather than a class-wide shared one. So rex.add_trick("sit") only ever touches rex's own tricks list, and fido.tricks correctly stays the empty list it was created with — no leakage between instances, which is exactly what the buggy version failed to guarantee.