Checkpoint

Checkpoint: The Guild Archive

The Guild archive is a maze of folders inside folders. Each folder is a dict. Each key is a name. Each value is either a number (a scroll with that many pages) or another dict (a folder inside).

archive = {
    "readme": 1,
    "maps": {"north": 3, "south": 5},
    "logs": {"2025": {"jan": 2, "feb": 4}},
}

Nobody knows how deep the folders go, so a fixed number of loops won't do. Recursion will: a folder inside a folder is just a smaller version of the same problem.

Assignment

Use recursion for both functions. Use isinstance(value, dict) to tell a folder from a scroll.

  1. total_pages(folder) returns the total pages of every scroll, however deep. For archive above it is 15.
  2. scroll_paths(folder) returns a list of paths to every scroll, in the order the dicts list them. Join names with "/". For archive above it is ["readme", "maps/north", "maps/south", "logs/2025/jan", "logs/2025/feb"].
  3. An empty folder has 0 pages and no paths ([]).