Skip to content

Stacks and queues · warm-up

The print queue

A printer takes jobs in the order they arrive. events is a list: a string adds that job to the queue, and None prints (removes) the oldest job.

Write print_order(events) returning the list of jobs in the order they were printed. A None with nothing waiting prints nothing.

Run adds print(print_order(["a", "b", None, "c", None, None])) after your code, to try it.

Stuck on the idea rather than the code? The Waiting in a stack, waiting in a queue lesson walks through it.