How to print lambda result ?

Barak, Ron Ron.Barak at lsi.com
Tue Jan 20 07:15:50 EST 2009


Hi,

Wanting to print the correct plural after numbers, I did the following:

for num in range(1,4):
    string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "")
    print string_

However, instead of getting the expected output:

1 event
2 events
3 events

I get:

1 event<function <lambda> at 0x00AFE670>
2 event<function <lambda> at 0x00AFE670>
3 event<function <lambda> at 0x00AFE6B0>

Reading the first results of http://www.google.com/search?q=python+lambda didn't enlighten me.

Could you point to a URL which could set me on the right path to get the expected output ?

Thanks,
Ron.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090120/8621daeb/attachment.html>


More information about the Python-list mailing list