
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
parse(line)returns a tuple(island, readings).readingsis a list ofints. Use star unpacking to split the island from the numbers, and a list comprehension to convert them.totals(lines)returns a dict that maps each island to the sum of its readings. Use a dict comprehension.dark_islands(lines)returns a set of the islands that have at least one0reading. Use a set comprehension.
parse(line)returns a tuple(island, readings).readingsis a list ofints. Use star unpacking to split the island from the numbers, and a list comprehension to convert them.totals(lines)returns a dict that maps each island to the sum of its readings. Use a dict comprehension.dark_islands(lines)returns a set of the islands that have at least one0reading. Use a set comprehension.
main.py Python sleeping
Press Run to try your code, then Check to test it.