What is the difference between two below definitions for lambda?

From the docs.

Filter takes a function and an iterable (list)
[i.e. filter(function, iterable)]

You are passing the lambda (lambda x:x=="Python") as the first argument here.

Max takes an iterable and (in this case) a single argument ‘key’ function
[i.e. max(iterable[, key])]

You are passing the lambda (lambda student: student.score) as the second, named, key argument.

Both your lambdas are the same lambda syntax. Perhaps you are confused because the second one uses the keyword argument (key=...) to pass the lambda to the function?

Browse More Popular Posts

Leave a Comment