gpt4 book ai didi

python - Lambda 函数翻译

转载 作者:行者123 更新时间:2023-11-30 22:51:10 40 4
gpt4 key购买 nike

我一直在努力处理一段我无法理解的Python代码。这是一个嵌套的 lambda 函数,如下所示:

lambda l: lambda x: x[0] in [None if not i.object else i.object.key for i in l]

我尝试翻译它,我想出了这个,但我认为这是不对的

 def f1(l):
def f2(x):
for i in l:
if not i.object:
return None
else
return x[0]

最佳答案

第 1 步:

def f1(l):
def f2(x):
xs = [None if not i.object else i.object.key for i in l]
return x[0] in xs
return f2

第 2 步:

def f1(l):
def f2(x):
xs = []
for i in l:
if not i.object:
xs.append(None)
else:
xs.append(i.object.key)
return x[0] in xs
return f2

关于python - Lambda 函数翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39098549/

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