1. Learn
  2. /
  3. Courses
  4. /
  5. Parallel Programming with Dask in Python

Connected

Exercise

Constructing custom Dask bags

A common use case for Dask bags is to convert some code you have already written to run in parallel. Depending on the code, sometimes it can be easier to construct lists of delayed objects and then convert them to a bag. Other times it will be easier to form a Dask bag early on in the code and map functions over it. Which of these options is easier will depend on your exact code, so it's important that you know how to use either method.

dask has been imported for you, and dask.bag has been imported as db. A list of file names strings is available in your environment as wavfiles.

Instructions 1/2

undefined XP
  • 1
    • Convert the list of filenames into a Dask bag.
    • Create a new bag of loaded audio data using the load_wav() function you wrote.
  • 2
    • Loop over the files and apply a delayed version of the load_wav() function to each file in wavfiles, appending the result to delayed_loaded_audio.
    • Convert the list of delayed objects to a Dask bag.