Reputation: 1587
>>> from multiprocessing import Pool
>>> def f(x, y):
... return x*y
>>> p = Pool(3)
>>> p.map(f, [1,2,3], [4,5,6])
And I look errors TypeError: unorderable types: list() <= int()
.
How to use Pool
with 2 lists?
Upvotes: 4
Views: 2555
Reputation: 2351
The problem is with the map
function not the Pool
object. For this case, starmap
would be a good choice like this:
p.starmap(f, zip([1,2,3], [4,5,6]))
From python 3.3 starmap
was added to the Pool
object
Upvotes: 6
Reputation: 507
I don't really understand how you want to order your parameters but the idea is to have a list of tuples because your function takes 2 arguments, so something like this :
p.map(f, [(1, 4), (2, 5), (3, 6)])
and make f take a tuple as argument
def f(t):
return t[0] * t[1]
Upvotes: 1