Re: Python had a little lambda ...

Steven D. Majewski (sdm7g@elvis.med.virginia.edu)
Wed, 23 Feb 1994 18:59:20 -0500

On Feb 23, 18:31, Nick Seidenman wrote:
>
> The recent discussion about collecting attributes using the lambda
> operator(?) brings up an interesting question. Lambda is not documented
> anywhere in the faq or "manuals" that come with the distrib. I know, I
> could peruse the source (no, please, not that!!!), but is python.lambda
> functionally, and syntactically (if not semantically)
> the same as lisp.lambda? Is it's use documented anywhere? If not, tutorial
> (however brief), please?
>

The Python syntax is:
lambda <parameters> : <expression>

as in:
>>>plus1 = lambda x : x+1
>>>plus1( 2 )
3
or:
>>>map( lambda x,y : x + y, range( 0, 10 ), [ 10 ] * 10 )
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

"lambda" is mentioned in the _latest_version_ of the Language Reference Manual:
section 5.9 "Boolean operations" ( page 29 in my copy - this one is in
the index under "lambda" )
section 7.5 "Function definitions" ( page 42, this one wasn't in my
index, but it was referenced in the entry above. )

In the Misc/NEWS file ( it was a new addition to 1.0 )

Tim said it was in the FAQ, but I didn't grep it.
Maybe he meant the NEWS file.

Map, filter, & reduce: new functions that can use "lambda" useful
are in the new version of the Library Reference Manual.

[ xrange is also mentioned in the Misc/NEWS file, but I didn't
see any mention of it in the library manual. ]

- Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU>
- UVA Department of Molecular Physiology and Biological Physics