I was wondering if there is anyway to run several threads and assign the results of different thread to specific keys in dict. Something like this:
from joblib import Parallel, delayed
from math import sqrt
dict_of_sqrt = {}
i = {'a':1,'b':2,'c':3,'e':4}
dict_of_sqrt[k] = Parallel(n_jobs=2)(delayed(sqrt)(v**2) for k, v in i.items())
The result should be the dictionary with the same keys and assigned new values calculated in parallel:
dict_of_sqrt = {'a':1, 'b':1.41, 'c'=1.73, 'e'=2}
It suppose to be safe, because I am writing to different keys (without overlapping). However, I have not found an example.