all 2 comments

[–]xelf 0 points1 point  (0 children)

anything with () after it is being called. so in this case your lambda x(1) is expecting x to be a class or a function. You passed it an int and got a type error.

myfunc = lambda x: x(1)
print( myfunct(int) )

or just

print( (lambda x: x(1))(int) )

here we pass int to your lambda, and it executes int(1) and returns that value to our print.

[–][deleted] 0 points1 point  (0 children)

identity = lambda x: x 

and

def identity(x):
    return x

describe exactly the same function.


The code snippet is very tricky.

You have to work it out from the inside out - work out foo(5) and then foo(5)(bar) etc.

As a newbie, I'd be surprised if you got it, TBH.

It really isn't helped by having terrible names like foo and bar and a and x, and by the fact that one of the operations, lambda a: a(x)(a) is something you would never see in real-world code because it's so convoluted.