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


Groups > comp.lang.python > #74176 > unrolled thread

Re: NaN comparisons - Call For Anecdotes

Started byChris Angelico <rosuav@gmail.com>
First post2014-07-09 01:31 +1000
Last post2014-07-09 01:31 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#74176 — Re: NaN comparisons - Call For Anecdotes

FromChris Angelico <rosuav@gmail.com>
Date2014-07-09 01:31 +1000
SubjectRe: NaN comparisons - Call For Anecdotes
Message-ID<mailman.11635.1404833503.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web