Simulate Concurrent Downloads
Medium
Write a function run_downloads(tasks) where tasks is a list of (name, delay) tuples. Using the threading module, start a thread for each task that sleeps for `delay` seconds then appends `name` to a shared results list. Wait for all threads to finish and return the results list (order may vary).
Input
A list of (name, delay) tuples, e.g. [("A", 0.1), ("B", 0.05)].
Output
A list containing each name once, after all threads complete.
Example
Input
[("A", 0.05), ("B", 0.02)]
Output
['B', 'A'] (order depends on delay)
Create a Thread for each task with a target function that sleeps then appends to a shared list. Start all threads, then join() each one before returning.
20 XP on solve
Back to lesson
Your Solution
Output
Click "Run" to execute your code...
⏳ Loading Python runtime (first run may take a few seconds)...
Log in to submit your solution and earn XP.