Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'explicitly': 0.05; 'float': 0.07; 'check,': 0.09; 'iterate': 0.09; 'keys,': 0.09; 'lookup': 0.09; 'themselves,': 0.09; 'cc:addr:python-list': 0.11; 'dict': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterating': 0.16; 'iteration': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'wed,': 0.18; "python's": 0.19; 'cc:addr:python.org': 0.22; 'skip': 0.24; 'cc:2**0': 0.24; 'compare': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; '(like': 0.30; 'message-id:@mail.gmail.com': 0.30; 'equality': 0.31; 'keys': 0.31; 'up:': 0.31; 'quite': 0.32; 'equal': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'should': 0.36; 'checks': 0.38; 'rather': 0.38; 'does': 0.39; 'skip:x 10': 0.40; 'results': 0.69; 'jul': 0.74; 'subject:For': 0.78; 'intern': 0.84; 'approach.': 0.91; 'crucial': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=JmoZI+Z3l+eIBrz2WfgvVYllHXApE3o7LdLd6+hIaz4=; b=VeICS9NUFByUvb9bKrA2aU4YY3ulQcgX6vVnLWM3tqeIk1P2W4ZM3t5mM5bNfCt43V FYmymSgmttLtQ9hjMXcOVEGCHzfV8UpWWOIiaF1NvXVQpZ+sCtj2qc9OKeFro0K2kZFs CGHa8oE+IZcOX3v6oIS5qK7xysIumH9SbrvSbf8YIJxyeyOoJ81Y4DDQHySW4GQKVU65 rrvSzU7B6YEx2drd/j7qoz6ghcgk+llJxz8Rmtsy5VfnMZx5txCSOw7c8lRbITHu9ju+ wBgVgs5NCT48thZJVllhTxP6jlnOYRKOEmObnCidUVoz51Er1VQtt0640tjBEzzwxLRs uI2g== MIME-Version: 1.0 X-Received: by 10.220.137.145 with SMTP id w17mr992078vct.47.1404833501109; Tue, 08 Jul 2014 08:31:41 -0700 (PDT) In-Reply-To: References: <53BC05FB.4050707@jmunch.dk> Date: Wed, 9 Jul 2014 01:31:41 +1000 Subject: Re: NaN comparisons - Call For Anecdotes From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1404833503 news.xs4all.nl 2903 [2001:888:2000:d::a6]:45363 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74176 On Wed, Jul 9, 2014 at 1:24 AM, Skip Montanaro wrote: > On Tue, Jul 8, 2014 at 10:19 AM, Chris Angelico wrote: >> For hash keys, float object identity will successfully look them up: >>>>> d={} >>>>> d[float("nan")]=1 >>>>> d[float("nan")]=2 >>>>> x=float("nan") >>>>> d[x]=3 >>>>> d[x] >> 3 >>>>> d >> {nan: 1, nan: 2, nan: 3} > > Neat! Yeah. It's one of those arguable points; is it a mere optimization that dict lookup does an identity check before an equality check, or is it crucial to other invariants (like the iteration one - if you iterate over items(), it should give exactly the same results as iterating over keys() and then looking things up)? Obviously it's better for the dict to use equality checks rather than identity checks (otherwise, at the very least, you'd have to explicitly intern all strings used as dict keys - that'd just be ridiculous), but with objects that don't compare equal to themselves, what should be done? I think Python's picked a quite reasonable approach. ChrisA