August 2021
Beginner to intermediate
118 pages
1h 29m
English
| Puzzle 4 | A Task to Do |
| 1: | from heapq import heappush, heappop |
| - | |
| - | tasks = [] |
| - | heappush(tasks, (30, 'work out')) |
| 5: | heappush(tasks, (10, 'wake up')) |
| - | heappush(tasks, (20, 0xCAFFE)) |
| - | heappush(tasks, (20, 'feed cat')) |
| - | heappush(tasks, (40, 'write book')) |
| - | |
| 10: | while tasks: |
| - | _, payload = heappop(tasks) |
| - | print(payload) |
Guess the Output | |
|---|---|
|
|
Try to guess what the output is before moving to the next page. |
This code will raise a TypeError exception.
The built-in heapq module implements min-heap over lists.
It’s common to ...
Read now
Unlock full access