+ 2
why use lambdas functions?
Wouldn't this be more simple: x = -4 print(x**2 + 5*x + 4) instead of this: print((lambda x: x**2 + 5*x + 4) (-4))
3 Respostas
+ 4
Lambdas are useful when you want to pass some action to execute to another function. Typical cases are filter() and map(), they apply some action to the elements of a list, in order to realise a transformation of that list. They abstract the transformation and this way they can be used for any particular transformation. Lambdas here are a very practical way to define a particular action in the same line you invoke the outer function, without having to define a whole new function for it. This is a significant case for lambdas, because usually actions for filters and mappings are trivial bits of code and writing them inline is very useful.
+ 1
lambda function are used when there is an single line expression to return from a function,and with map and filter it is precise way of writing functions and extracting values out of iterables.