我想使用带有多个参数的 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]
关于python - imap函数: passing a list and a another fixed string as argument (Python 3. 7/3.8),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59989907/