checking for negative values in a list

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Mon Dec 17 09:36:17 EST 2007


On Mon, 17 Dec 2007 06:20:23 -0800, vimal wrote:

>    i have a list of numbers
> 
>   say a = [1,-1,3,-2,4,-6]
> 
>   how should i check for negative values in the list

In [6]: a = [1, -1, 3, -2, 4, -6]

In [7]: any(n < 0 for n in a)
Out[7]: True

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list