On 3/12/2013 1:03 PM, Norah Jones wrote:
For example:
a=[-15,-30,-10,1,3,5]

I want to find a negative and a positive minimum.

example: negative
print(min(a)) = -30

positive
print(min(a)) = 1

If this is homework, stop reading and do it yourself ;-)
Otherwise...
>>> min(i for i in a if i >0)
1
>>> max(i for i in a if i < 0)
-10
>>> min(i for i in a if i < 0)
-30

You did not specify if you would include 0 in a pos min (0 is neither really positive or negative).

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to