There are a lot of tutorials for Python’s lambda out there. A very helpful one is Mike Driscoll’s discussion of lambda on the Mouse vs Python blog. Mike’s discussion is excellent: clear, straight-forward, with useful illustrative examples. It helped me — finally — to grok lambda, and led me to write yet another lambda tutorial.
Lambda is a tool for building functions
Lambda is a tool for building functions, or more precisely, for building function objects. That means that Python has two tools for building functions: def and lambda.
Here’s an example. You can build a function in the normal way, using def, like this:
or you can use lambda:
Here are a few other interesting examples of lambda:
What is lambda good for? Why do we need lambda?
Actually, we don’t absolutely need lambda; we could get along without it. But there are certain situations…
View original post 1,906 more words