what's wrong with "lambda x : print x/60,x%60"

Mohammad Jeffry linuxlah at gmail.com
Mon Dec 5 01:32:45 EST 2005


without the "print" also gives me error:-

>>> lambda_hrs = lambda x : x/60,x%60
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'x' is not defined


On 12/5/05, Mohammad Jeffry <linuxlah at gmail.com> wrote:
>
> Dear All,
>
> Can't a lambda uses the input parameter more then once in the lambda body?
>
> eg:
> lambda x : print x/60,x%60
>
> I tried with def and it works but got syntax error with lambda. Below is
> an interactive sample:
>
> linuxlah at algorhythm ~ $ python
> Python 2.4.2 (#1, Nov 18 2005, 19:32:15)
> [GCC 3.3.6 (Gentoo 3.3.6, ssp-3.3.6-1.0, pie-8.7.8)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> def func_hrs(x): print x/60,x%60
> ...
> >>> func_hrs(400)
> 6 40
> >>> lambda_hrs = lambda x : print x/60,x%60
>   File "<stdin>", line 1
>     lambda_hrs = lambda x : print x/60,x%60
>                                 ^
> SyntaxError: invalid syntax
> >>>
>
> My main concern is how can I do this in lambda?
>
>
>
> --
> And whoever does an atom's weight of evil will see it.




--
And whoever does an atom's weight of evil will see it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051205/557b1620/attachment.html>


More information about the Python-list mailing list