Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4a.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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'operator': 0.03; 'sufficient': 0.05; '[1,': 0.09; 'language.': 0.14; 'changes': 0.15; 'compares': 0.16; 'equal.': 0.16; 'nan': 0.16; 'nans': 0.16; 'semantics': 0.16; 'subject:operators': 0.16; 'token,': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'written': 0.21; '>>>': 0.22; 'proposed': 0.22; 'nearly': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; 'comparison': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'though.': 0.31; 'supposed': 0.32; "we're": 0.32; 'up.': 0.33; 'used,': 0.33; 'could': 0.34; 'problem': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'data,': 0.36; 'false': 0.36; "he's": 0.36; 'doing': 0.36; 'should': 0.36; 'two': 0.37; 'requiring': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'solve': 0.60; 'most': 0.60; 'talking': 0.65; 'equals': 0.68; 'jul': 0.74; 'subject:Proposal': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=GtMVYE/eqY3vK6fTmbW/4LGPLwvm9lcvaQ/xTXrqIt8=; b=hslGDG7y/Qq6qI2oPi7UtDKnf/XIOYyvTFEDrJJPBPrxaP+OF2Zt8ez/lYHSrNKPo/ YSl7kQ78X4YQhz/54je3zJBmZcKjjH2AN+rMxU92QedoyktWufB5ncn6+RKYlL0YuI5K +RVaBvomgVx3PZPon+AkhqCsLEb/SQ5WMrt3F8+Ko1+4g9F/J2+k7J/pGaWZFQL28CJ4 nTi+clh5s8vJD3Da8qmT7uV1/Tj6ms+FcHPmCrrI4fmT0DiXQy7FWrLPwALeipnI/6L1 cfWXHjvNjcbMdEU2e67LAkJnevosdO7BS1+jP3GYo5YBYCpncQy8Ed5pRncBlNG0ebep uYUQ== X-Received: by 10.66.136.131 with SMTP id qa3mr41722106pab.77.1404928241620; Wed, 09 Jul 2014 10:50:41 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <53bd08b4$0$2746$c3e8da3$76491128@news.astraweb.com> References: <53bce8a3$0$2746$c3e8da3$76491128@news.astraweb.com> <53bd08b4$0$2746$c3e8da3$76491128@news.astraweb.com> From: Ian Kelly Date: Wed, 9 Jul 2014 11:50:01 -0600 Subject: Re: Proposal: === and !=== operators To: Python 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1404928249 news.xs4all.nl 2918 [2001:888:2000:d::a6]:41009 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74268 On Wed, Jul 9, 2014 at 3:17 AM, Steven D'Aprano wrote: > People are already having problems, just listen to Anders. He's > (apparently) not doing NAN-aware computations on his data, he just wants > to be able to do something like > > this_list_of_floats == that_list_of_floats > > without NANs screwing it up. But by the same token, if I want to use NANs > the way they're supposed to be used, I should still be able to use an > equals operator (rather than a function or method). Well, if we're talking about *lists*, then the comparison operator already compares identity of individual elements: >>> nan = float('nan') >>> l1 = [1.0, 2.0, nan, 4.0] >>> l2 = [1.0, 2.0, nan, 4.0] >>> l1 == l2 True So the comparison "x is y or x == y" could also be written "[x] == [y]", without requiring any changes to the language. I suspect that just adding identity comparison is not sufficient to solve Anders' problem, though. > But the problem is, most people will need to us "x is y or x == y" nearly > everywhere! And that doesn't help with containers: > > py> alist = [1.0, 2, float('NAN'), 4] > py> blist = [1, 2.0, float('nan'), 4] > py> alist is blist or alist == blist > False The only reason this fails is because the two nans are neither identical nor equal. The proposed == semantics would also fail here.