user3253067 user3253067 - 3 months ago 18
Python Question

Lambda function translation

I have been struggling with a piece of python code that i can not make sense of.
It's about a nested lambda function that looks like this:

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


I have tried to translate it and i came up with this but i do not think this is right

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

Answer

Step 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

Step 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
Comments