Queues and Deques
A queue is a line where the first item in is the first out (FIFO), like people at a bank. New items join at the back (enqueue) and leave from the front (dequeue).
Do not use list.pop(0) for a queue: removing from the front of a list is O(n). Python's collections.deque removes from both ends in O(1): append to join, popleft to leave.
Examplepython
Quick check
Which end does `popleft()` remove from?
Your turn: write the code
Simulate a printer queue. Jobs arrive in the order given and are printed first come, first served. Print the job names in the order they print, joined with commas.
Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.
Tip: use the left and right arrow keys to move between lessons.