[Tutor] filtering NaN values

Kent Johnson kent37 at tds.net
Tue Jun 23 02:43:55 CEST 2009

On Mon, Jun 22, 2009 at 4:15 PM, Elisha Rosensweig<benshafat at gmail.com> wrote:
> Hi,
> 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) ]

In older versions of Python I don't know how to do this.


More information about the Tutor mailing list