Lesson 12.5
A queue is like a shop: you join the end, you are served from the front. First in — first out.
from collections import deque
queue = deque()
queue.append("homework") # to the end
queue.append("game")
queue.popleft() # "homework" — from the front
append adds to the end, popleft takes from the front;pop() takes from the end — that's a stack, not a queue;deque: in a list list.pop(0) shifts all the items every time.The check gives the list of tasks tasks and the number handled — how many tasks get
done, and the list of new ones added, which join the end. Write the processing and print
Doing: <task> for each one done, then Left: <how many> tasks.
The queue comes from collections: deque(list), adding is extend.
Items are taken from the front with popleft(), not pop(). Do handled
steps with a for loop, and len(queue) shows what is left.