OneBug This week's bugs
Spot the bug Python
1
# Drop every pending task from the queue.
2
def clear_pending(tasks):
3
    for t in tasks:
4
        if t["status"] == "pending":
5
            tasks.remove(t)
6
    return tasks
7
 
8
queue = [
9
    {"id": 1, "status": "done"},
10
    {"id": 2, "status": "pending"},
11
    {"id": 3, "status": "pending"},
12
    {"id": 4, "status": "done"},
13
]
14
print([t["id"] for t in clear_pending(queue)])
15
# expected: [1, 4]
16
# actual:   [1, 3, 4]  (!)

Read the full write-up for this bug (spoilers)