Checkpoint

Checkpoint: The Cargo Manifest

The Guild airship is loading crates for Skyreach Isle. The quartermaster wants a typed cargo manifest, so that editors and type checkers can catch mistakes before take-off.

This checkpoint mixes the tools from this chapter: a TypedDict, container types like list[str], X | None for "maybe a value", and a generic function with a type parameter.

Assignment

  1. Make Crate a TypedDict with three keys: label (str), weight (int) and fragile (bool).
  2. heaviest(crates: list[Crate]) -> Crate | None returns the crate with the biggest weight, or None if the list is empty.
  3. fragile_labels(crates: list[Crate]) -> list[str] returns the labels of the fragile crates, in order.
  4. pick[T](items: list[T], index: int) -> T | None returns items[index], or None if index is out of range. Use the new bracket syntax for T. (Don't worry about negative indexes.)