Jump to content

Lambda (programming)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by JaGa (talk | contribs) at 23:31, 28 December 2010 (create from content in Lambda (disambiguation)). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

In programming languages such as Lisp and Python, lambda is an operator used to denote anonymous functions or closures, following the usage of lambda calculus. An example of this use of lambda in the Python language is this section of computer code that sorts a list alphabetically by the last character of each entry:

>>> stuff = ['woman', 'man', 'horse', 'boat', 'plane', 'dog']
>>> sorted(stuff, key=lambda word: word[-1])
['horse', 'plane', 'dog', 'woman', 'man', 'boat']