470,841 Members | 883 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,841 developers. It's quick & easy.

lambda

what is a lambda expression?

Aug 24 '06 #1
3 2142
fegge wrote:
what is a lambda expression?
that's explained in the documentation, of course; see e.g.

http://pyref.infogami.com/lambda

</F>

Aug 24 '06 #2
fegge wrote:
what is a lambda expression?
You really should try Google first (python lambda):

http://www.secnetix.de/~olli/Python/...functions.hawk
http://diveintopython.org/power_of_i...functions.html

-Larry
Aug 24 '06 #3
what is a lambda expression?
labmda is a reserved word and AFAIK it is an operatior.
By using lamba, you can create an anonymous function. That is, a
function without name.

For example, doing

def create_adder(amount):
def adder(x):
return x + amount
return adder
is equvalent to:

def create_adder(amount):
return lambda x : x + amount

In the former case:
>>f1 = create_adder(4)
f1
<function adder at 0x00BE6930>
>>f1(2)
6

In the later case:
>>f2 = create_adder(4)
f2
<function <lambdaat 0x00BE66F0>
>>f2(2)
6

For example, if you want create a new list by adding 4 to the elements
of another list:
>>another = [1,2,3,4,5]
newlist = map( lambda x: x+4 , another)
newlist
[5, 6, 7, 8, 9]

Best,

Laszlo

Aug 24 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

53 posts views Thread by Oliver Fromme | last post: by
63 posts views Thread by Stephen Thorne | last post: by
26 posts views Thread by Steven Bethard | last post: by
4 posts views Thread by Xah Lee | last post: by
23 posts views Thread by Kaz Kylheku | last post: by
5 posts views Thread by Octal | last post: by
21 posts views Thread by globalrev | last post: by
1 post views Thread by Tim H | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.