[Tutor] filtering NaN values

Alan Gauld alan.gauld at btinternet.com
Tue Jun 23 07:53:59 CEST 2009


"Kent Johnson" <kent37 at tds.net> wrote

>> I have a list with some values being NaN (after division-by-zero). How 
>> can I
>> check and remove all the NaN values?
>
> In Python 2.6 you can use math.isnan() to check for NaN, so you can
> filter your list by
> newList = [ x for x in oldList if not math.isnan(x) ]

Interesting! How is a NaN stored in Python?
ie. How do you get to the point of having one in the first place?

Python continues is symbiosis with JavaScript...


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 




More information about the Tutor mailing list