Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74176

Re: NaN comparisons - Call For Anecdotes

References <53BC05FB.4050707@jmunch.dk> <CAPTjJmoD5gfwpcW_45bzO846gFYMGH6+9TYowSea0SPpe-o__A@mail.gmail.com> <CANc-5UxEt1f03n5xu1R8bAtOBTMnxnSD88eA95dn3pCvaE13gA@mail.gmail.com>
Date 2014-07-09 01:31 +1000
Subject Re: NaN comparisons - Call For Anecdotes
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.11635.1404833503.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Jul 9, 2014 at 1:24 AM, Skip Montanaro <skip@pobox.com> wrote:
> On Tue, Jul 8, 2014 at 10:19 AM, Chris Angelico <rosuav@gmail.com> 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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: NaN comparisons - Call For Anecdotes Chris Angelico <rosuav@gmail.com> - 2014-07-09 01:31 +1000

csiph-web