Deep independence

Step 2 - Deep independence

A shallow copy would share the tags list between the original and the clone, so appending to one would change the other. Make clone() perform a true deep copy so nested mutable data is fully independent.

Fix clone() to use copy.deepcopy. After cloning, mutating either side's tags list must not affect the other.

Hints
Starter code
import copy


class Entity:
    def __init__(self, name, tags=None):
        self.name = name
        self.tags = list(tags) if tags is not None else []

    def clone(self):
        """Return an independent copy of this entity."""
        # TODO: use copy.deepcopy so the tags list is not shared
        return copy.copy(self)
Write it on a laptop

The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.