[Tutor] Applications/examples of some advanced Py
features, please !
Bob Gailer
ramrom@earthling.net
Fri Jan 3 17:47:02 2003
--=======41CB536C=======
Content-Type: text/plain; x-avg-checked=avg-ok-1CF2B71; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit
Regarding lambda, it is an abbreviated way of defining a function. The
limitation is that the body of the function is one expression whose value
is returned.
f = lambda x, y:x+y
is the same as
def f(x, y):
return x+y
It is useful when you only need to refer to the function once, as in:
filter(lambda x:x>5, some-sequence-of-numbers)
That's all I have to say about lambda, except that, if you want to use it
with list comprehension the syntax is a little tricky:
[(lambda x:x>5)(item) for item in some-sequence-of-numbers]
Bob Gailer
mailto:ramrom@earthling.net
303 442 2625
--=======41CB536C=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-1CF2B71
Content-Disposition: inline
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.431 / Virus Database: 242 - Release Date: 12/17/2002
--=======41CB536C=======--