[Tutor] lambda and map
Pedro Diaz Jimenez
pdiaz88@terra.es
Sun, 27 May 2001 01:11:17 +0000
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Thats because map needs a funcition, like reduce or filter. lambda functions
are the fast food of programming: not much content, but you can use it
inmediatlly
say you wanna filter [1,2,3,4,5,6] taking away the odd numbers
if you don't use lambda, you have to
def isOdd(n):
blah
blah
filter( isOdd, [1,2,3,4,5] );
With lambda calculus, is just:
>>> filter( lambda x: (x%2)==0, [1,2,3,4,5,6] )
[2, 4, 6]
>>>
voila!
Cheers
Pedro
On Saturday 26 May 2001 22:13, Timothy M. Brauch wrote:
> Okay, I am now what I would call competent in Python. But, I keep
> noticing (learning) some new stuff every time I get an email from
> tutor. There is, however, one thing I am not really sure about,
> lambda. I don't quite understand what a lambda does or why to use it.
> I think I understand map, more or less, but the two are often seen
> together.
>
> - Tim
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
- --
/*
* Pedro Diaz Jimenez
* pdiaz88@terra.es
* pdiaz@acm.asoc.fi.upm.es
*
* Wanna see how 100000! looks like?:
* http://acm.asoc.fi.upm.es/~pdiaz/fact_100.000
*
* La sabiduria me persigue, pero yo soy mas rapido
*
*/
Random quote:
- -------------
After your lover has gone you will still have PEANUT BUTTER!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE7EFQ1nu53feEYxlERAhqcAKDOJ7iQXQ/+4iIY+xYAToe29NywvgCgwcmu
PetmNNTZthZ8PwPbCYZv71A=
=CPXd
-----END PGP SIGNATURE-----