python - imap函数: passing a list and a another fixed string as argument (Python 3. 7/3.8)

标签 python arguments

我想使用带有多个参数的 imap 函数。目前我只是使用:

...   
p.imap(function, iterated_list_for_first_argument)

但我想让它与另一个预定义的固定字符串参数一起作为第二个参数。 像这样:

...   
p.imap(function, iterated_list_for_first_argument, second argument)

如果我理解正确的话,imap 函数不会接受两个参数。

最佳答案

您可以使用itertools.chainiterated_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/

相关文章:

python - 在 matplotlib 中保存 .imshow() 之后的子图

c++ - 在模板参数推导中, sqrt<T>(complex<T>) 如何匹配 sqrt<T>(<T>) 函数调用?

python - 如何在十六进制Linux终端中发送参数

swift - 将 [Float] 转换为变量参数

python - 在python opencv模块中编辑后保存同名图像

python - 向量化分组求和

python - 使用 minidom 获取元素的所有属性

default - 如何使用变量作为 TCL proc 参数的默认值

ios - 协议(protocol)方法/函数中的 Swift 默认参数和忽略参数

python - 如何在Debian 10上安装python3.8?