Home / Challenges / Simulate Concurrent Downloads

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)
20 XP on solve Back to lesson

Your Solution

Output
Click "Run" to execute your code...

Log in to submit your solution and earn XP.