Checkpoint

Checkpoint: The Beacon Pipeline

Beacon towers across Pythonia send brightness readings to the Guild. Some towers never stop sending! Pip needs a lazy pipeline that joins the towers, keeps only the bright readings, and stops after a few.

You'll use every tool from this chapter: a generator function, yield from, a generator expression and islice.

towers = [[3, 9], [12, 1, 8]]
print(first_bright(towers, 5, 2))  # [9, 12]

Assignment

  1. all_readings(towers): a generator that uses yield from to hand out every reading of every tower, in order.
  2. bright(readings, limit): return a generator expression of the readings that are bigger than limit.
  3. first_bright(towers, limit, n): return a list of the first n bright readings. Connect the two stages and use islice. It must work even if a tower never stops sending.