Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feed.xsnews.nl!border-1.ams.xsnews.nl!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'true,': 0.04; 'float': 0.05; 'means,': 0.07; 'valueerror:': 0.07; 'python': 0.09; 'cc:addr:python-list': 0.10; 'itself.': 0.11; 'index': 0.13; 'anna': 0.16; 'compares': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'handling.': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'nan': 0.16; 'received:202.125.174': 0.16; 'received:202.125.174.133': 0.16; 'received:boardofstudies.nsw.edu.au': 0.16; 'received:cskk.homeip.net': 0.16; 'received:edu.au': 0.16; 'received:harvey.boardofstudies.nsw.edu.au': 0.16; 'received:homeip.net': 0.16; 'received:nsw.edu.au': 0.16; 'simpson': 0.16; 'subject:fails': 0.16; 'unequal,': 0.16; 'url:py3k': 0.16; 'wrote:': 0.17; 'detect': 0.17; '>>>': 0.18; '"",': 0.22; 'bug?': 0.22; 'cheers,': 0.23; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:[ 10': 0.26; '(most': 0.27; '2.6': 0.27; 'instead.': 0.27; '3.1': 0.29; 'relies': 0.29; "i'm": 0.29; 'function': 0.30; 'point': 0.31; 'url:python': 0.32; 'file': 0.32; 'traceback': 0.33; 'values.': 0.33; 'know.': 0.33; 'list': 0.35; 'returning': 0.35; 'but': 0.36; 'url:org': 0.36; 'received:au': 0.36; 'url:library': 0.36; 'test': 0.36; 'charset:us-ascii': 0.36; 'subject:: ': 0.38; 'url:docs': 0.38; 'content-disposition:inline': 0.60; 'email addr:gmail.com': 0.63; 'making': 0.64; 'special': 0.73; 'correctly?': 0.84; 'russell': 0.84 Date: Fri, 26 Oct 2012 13:15:45 +1100 From: Cameron Simpson To: mamboknave@gmail.com Subject: Re: a.index(float('nan')) fails MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) References: Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351217756 news.xs4all.nl 6941 [2001:888:2000:d::a6]:33837 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32181 On 25Oct2012 18:46, mamboknave@gmail.com wrote: | >>> a = [float('nan'), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | >>> a | [nan, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | >>> a.index(float('nan')) | Traceback (most recent call last): | File "", line 1, in | ValueError: list.index(x): x not in list | | That means, the function .index() cannot detect nan values. | It happens on both Python 2.6 and Python 3.1 | | Is this a bug? Or I am not using .index() correctly? The special NaN float value always compares unequal, even to itself. IEEE floating point FTW! You're using index incorrectly, but only because it relies on == returning True, which it won't. You can use math.isnan: http://docs.python.org/library/math.html#math.isnan http://docs.python.org/py3k/library/math.html#math.isnan for the test instead. Nan requires special handling. Cheers, -- Cameron Simpson I'm not making any of this up you know. - Anna Russell