lambda functions

alex23 wuwei23 at gmail.com
Tue Sep 1 07:53:05 CEST 2009


Pierre <pierre.gaill... at gmail.com> wrote:
> I would like to know if it is possible to define a loop in a lambda
> function....

It is if you can easily replace the for loop with a call to map():

>>> s_minus_1 = lambda s: map(lambda x: x-1, s)
>>> test = range(1, 100, 10)
>>> test
[1, 11, 21, 31, 41, 51, 61, 71, 81, 91]
>>> s_minus_1(test)
[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]



More information about the Python-list mailing list