Purpose of asterisk in dask.compute()

This may be a stupid question…
What is the purpose of asterisk in dask.compute() like below?

result = dask.compute(*some_list)

Thanks,

Hi,

* is, among others, the unpacking operator in Python. So in this case, it allows to unpack the list and make each element of the list an argument to dask.compute call.
dask.compute will return a tuple of the computation results of each of its input argument. Not unpacking the list will work, because Dask is able to traverse the arguments that are collections (see the doc), however, the result won’t be identical.

Let’s see with an example, consider lazy_results as a list containing Delayed objects:

dask.compute(*lazy_results)

will return a tuple of results, for example:

(2.3076699272644765,
 2.5440502721750455,
 2.744212952950088,
 1.9135732807949462)

Whereas

dask.compute(lazy_results)

will return a tuple containing a list of results:

([2.3076699272644765,
  2.5440502721750455,
  2.744212952950088,
  1.9135732807949462],)
1 Like