On Aug 22, 6:33 pm, David Philp <[EMAIL PROTECTED]> wrote:

> >>>> map(lambda x: x>0 and x or 0, data)
> > [0, 2, 3]
>
> Can someone translate that "lambda x: x>0 and x or 0" into William's
> "the words in your head" please?

I suspect this is coming from someone who learned python before it
acquired a conditional expression and illustrates why it was
introduced.

The alternative
>>> map(lambda x: x if (x>0) else 0, data)
reads a little more comfortably for me as:
"Apply the function that, given x, returns x itself if x>0 and 0
otherwise, to each element of data"

It is rather cool to see that the whole ... if ... else ... construct
is not necessary and that the
... ? ... : ... from C can be encoded in the exact same order in
python if you are willing to read ? for "and" and : for "or".
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to