我想使用带有多个参数的 imap
函数。目前我只是使用:
...
p.imap(function, iterated_list_for_first_argument)
但我想让它与另一个预定义的固定字符串参数一起作为第二个参数。像这样:
...
p.imap(function, iterated_list_for_first_argument, second argument)
如果我理解正确的话,imap
函数不会接受两个参数。
您可以使用itertools.chain
将iterated_list_for_first_argument
与第二个参数
链接起来,例如:
from itertools import imap
from itertools import chain
iterated_list_for_first_argument = [[1,2], [1,2]]
second_argument = [[4]]
print list(imap(sum, chain(iterated_list_for_first_argument, second_argument)))
输出:
[3, 3, 4]
我是一名优秀的程序员,十分优秀!