One argument that is repeated, one argument in c
from itertools import repeat
for result in executor.map(f, repeat(a), c):
pass
Need to unpack items of c, and can unpack c
from itertools import izip
for result in executor.map(f, *izip(*c)):
pass
Need to unpack items of c, can’t unpack c
- Change
fto take a single argument and unpack the argument in the function. -
If each item in
chas a variable number of members, or you’re callingfonly a few times:executor.map(lambda args, f=f: f(*args), c)It defines a new function that unpacks each item from
cand callsf. Using a default argument forfin thelambdamakesflocal inside thelambdaand so reduces lookup time. -
If you’ve got a fixed number of arguments, and you need to call
fa lot of times:from collections import deque def itemtee(iterable, n=2): def gen(it = iter(iterable), items = deque(), next = next): popleft = items.popleft extend = items.extend while True: if not items: extend(next(it)) yield popleft() return [gen()] * n executor.map(f, *itemtee(c, n))
Where n is the number of arguments to f. This is adapted from itertools.tee.