gpt4 book ai didi

python - 在 python 中没有 lambda 的函数列表上映射函数应用程序

转载 作者:行者123 更新时间:2023-11-28 22:42:29 25 4
gpt4 key购买 nike

我有以下代码:

def f1():
print("f1")

def f2():
print("f2")

flist = [f1,f2]

list(map(lambda x: x(), flist))

我需要去掉 lambda,因为它不能用 pickle 转储。

是否有任何函数或结构运行作为参数接收的函数?

这是我需要修改和删除辅助函数“call”的实际代码:

from multiprocessing import Pool
def call(x):
x()
p = Pool()
p.map(call, func_list)

最佳答案

你可以试试

[f() for f in flist]

希望这有帮助:)

关于python - 在 python 中没有 lambda 的函数列表上映射函数应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31670551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com