Command Palette

Search for a command to run...

Hectal
Phase 12: Concurrency and Async
Python · Exercise 1 of 6Next
Intermediate

Fetch many pages at once with gather

fake_fetch(name) pretends to download a page and returns "page:<name>". Write async def fetch_all(names) that fetches all the names at the same time with asyncio.gather and returns the list of pages in the same order as names.

An empty list gives []. The program should print ['page:a', 'page:b', 'page:c'].

What Check tests

  1. fetch_all(["a", "b", "c"]) returns the pages in order
  2. fetch_all([]) returns an empty list
  3. The four fetches overlap (all four in flight at once)
  4. The program prints the three pages

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.