On Aug 22, 10:43 am, Harald Schilly <[EMAIL PROTECTED]> wrote:
> >>> data = [-1,2,3]
> >>> gt0 = lambda x: x>0 and x or 0
> >>> map(gt0, data)
>
> [0, 2, 3]
>
> in python - or more geeky
>
> >>> map(lambda x: x>0 and x or 0, data)

I'm sorry for derailing the thread a little bit, but this is actually
a dangerous paradigm to code conditional expressions with (I know
because I did not see the catch myself until later either). Your code
would work, but in similar situations  (say, replace all 0's by 1's
and leave everything else the same) you might be tempted to write:

>>> data = [None, 0, 1]
>>> map(lambda x: x <>0 and x or 1, data)
[1, 1, 1]

The problem being that if x is considered false then 1 will be
returned anyway.

On a related note:
sage ints and python ints seem to differ in where they put None in
their ordering:

sage: None > 0
True
sage: None > int(0)
False

[I really would have appreciated an error here, but I guess Python
requires all objects to be comparable?]

--~--~---------~--~----~------------~-------~--~----~
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