PythiloLesson 7 of 20 · progress kept in this browser

Create independent default containers

A default value and a default factory express different intentions. A factory is called when an input omits the field, so it can produce a new container or a value computed at construction time. It also makes ownership of mutable state visible to a reader.

Pydantic protects many mutable defaults by copying them, but an explicit factory is clearer when fresh state is part of the contract. Supplied values still go through validation; the factory is not a general hook for transforming every input.

from pydantic import BaseModel, Field
class Bag(BaseModel):
    tags: list[str] = Field(
        default_factory=list)
a, b = Bag(), Bag()
a.tags.append("new")
print(a.tags, b.tags)
Your task

Implement independent_tags() constructing two Bag models with tags default_factory=list. Append "new" to the first and return their dumped dictionaries. Neither call may share accumulated state with another call.

The first run loads pydantic into this browser.