Checkpoint

Checkpoint: The Lantern Census

Once a year the Guild counts the fuel in every lantern. Each census line names an island, then the fuel in each of its lanterns: "Moss 3 5 0". Turn the census into answers, the Pythonic way.

This checkpoint uses the whole chapter: star unpacking and list, dict and set comprehensions. (The walrus is a bonus.)

Assignment

  1. parse(line) returns a tuple (island, readings). readings is a list of ints. Use star unpacking to split the island from the numbers, and a list comprehension to convert them.
  2. totals(lines) returns a dict that maps each island to the sum of its readings. Use a dict comprehension.
  3. dark_islands(lines) returns a set of the islands that have at least one 0 reading. Use a set comprehension.