2
import multiprocessing as mp
pool = mp.Pool()

As I understand it (please correct me if wrong):

  • map works on functions that take only one input parameter, and you can pass in a list of such single parameter to make multiple function calls
  • apply works on functions that can take multiple parameters, but you can only pass one tuple of such parameters to make one function call
  • starmap can deal with both multi-parameter functions and be passed in a list of tuples of parameters

Since starmap can handle what map and apply can, why does Python provide three functions instead of just one? In other words, what are the advantages of map and/or apply over starmap?

Update

As @coldspeed pointed out, it can just be backward compatibility. But this begs the question, and I guess this is what actually puzzles me: Why did python make both map and apply in the first place, what's so hard about allowing multi-parameter and a list of jobs at the same time?

Hope this is not closed due to being considered "primarily opinion based". There must be some reasons that can be universally appreciated why the original python developers made two functions each having its own limit instead of one single all-powerful one.

Indominus
  • 1,228
  • 15
  • 31

0 Answers0