Lambda calculus codifies the correct way to do these substitutions. Given that y = x−1 is a valid rearrangement of the second equation, this: λ y = x−1 means a function substituting the symbols x−1 for the symbol y. Now imagine applying λ y to each term in the first equation. If a term is y then perform the substitution; otherwise do ...
Here is another really good reference which explains very well what are lambda expressions in C++: Microsoft.com: Lambda expressions in C++. I especially like how well it explains the parts of a lambda expression, in particular: the capture clause, parameter list, trailing-return-type, and lambda body.
I saw some examples using built-in functions like sorted, sum etc. that use key=lambda. What does lambda mean here? How does it work? For the general computer science concept of a lambda, see What...
Lambda functions are most useful in things like callback functions, or places in which you need a throwaway function. JAB's example is perfect - It would be better accompanied by the keyword argument key, but it still provides useful information.
The lambda construct is a shorter way to define a simple function that calculates a single expression. The def statement can be inconvenient and make the code longer, broken up and harder to read through.
An easy way to perform an if in lambda is by using list comprehension. You can't raise an exception in lambda, but this is a way in Python 3.x to do something close to your example:
The closure of a lambda expression is this particular set of symbols defined in the outer context (environment) that give values to the free symbols in this expression, making them non-free anymore. It turns an open lambda expression, which still contains some "undefined" free symbols, into a closed one, which doesn't have any free symbols anymore.
Lambda is a means of creating an anonymous function or closure. In imperative languages (and functional ones) it is equivalent to allowing nested functions where the inner function has access to local variable and parameters of the enclosing function.
I don't quite understand the syntax behind the sorted() argument: key=lambda variable: variable[0] Isn't lambda arbitrary? Why is variable stated twice in what looks like a dict?
1 (lambda x: x%2) is a function, and dividing a function by 2 doesn't make any sense. You probably want to call it and divide what the value it returned.