Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '(at': 0.04; 'value,': 0.04; 'interpreter': 0.05; 'element': 0.07; 'occasionally': 0.09; 'part,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'changes': 0.15; 'at.': 0.16; 'defined.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'list),': 0.16; 'nan': 0.16; 'sorts': 0.16; 'subject:operators': 0.16; 'followed': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'putting': 0.22; 'cc:addr:python.org': 0.22; '"you': 0.24; "aren't": 0.24; 'comparing': 0.24; 'cc:2**0': 0.24; 'compare': 0.26; 'second': 0.26; 'least': 0.26; 'header:In-Reply-To:1': 0.27; '[1]': 0.29; '(like': 0.30; '[2]': 0.30; 'message- id:@mail.gmail.com': 0.30; 'alan': 0.31; 'comparison': 0.31; 'continues': 0.31; "d'aprano": 0.31; 'equality': 0.31; 'steven': 0.31; 'writes:': 0.31; 'lists': 0.32; 'text': 0.33; 'cases': 0.33; '"the': 0.34; 'problem': 0.35; 'equal': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'data,': 0.36; 'described': 0.36; 'done': 0.36; 'should': 0.36; 'list': 0.37; 'clear': 0.37; 'pm,': 0.38; '12,': 0.39; "couldn't": 0.39; 'either': 0.39; 'how': 0.40; 'most': 0.60; 'lost': 0.61; 'strictly': 0.61; 'myself': 0.63; 'more': 0.64; 'land': 0.65; 'details': 0.65; 'gathering': 0.68; 'fact,': 0.69; 'jul': 0.74; 'madness': 0.84; 'omission': 0.84; 'cast': 0.91; 'subject:Proposal': 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=w16nAqnIKPyXZ3qsvhvcUIEAWoujWDE02VeUYrny7Gw=; b=pnvAwOja0Bcx04aMrD1AZcrAZkg4F2Rao2FXCLVIixQiCV0d/TBVtr60wjAF+Om3zV 4zqNK4vkw4y/Vvz24iXPaCesUUfO+V9WpoBpMtBMcNc1DQgbxqQnpiq/IabFp5PZbeMa 5cQSQKV/BFcf94yTH7u03/YrVBE6m30Rii9rKtSR57NJmjyqed0uxhnlAgU4r7PaXHCx IiHOnnYl0QEyAkvf1inHHXi18/Nef5TH265m4sdzf8IjzEOXGgycH1eHE2EXg0UMItrv WI7PkFvEVghOCz5usoY99PWQLK+okrrpD4wQCpMVpoFWkSxyAeZWF1bARe6EdwATszCc abgg== MIME-Version: 1.0 X-Received: by 10.58.198.201 with SMTP id je9mr3733411vec.33.1405145211748; Fri, 11 Jul 2014 23:06:51 -0700 (PDT) In-Reply-To: References: <53bce8a3$0$2746$c3e8da3$76491128@news.astraweb.com> <53c0abe8$0$9505$c3e8da3$5496439d@news.astraweb.com> Date: Sat, 12 Jul 2014 16:06:51 +1000 Subject: Re: Proposal: === and !=== operators 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1405145213 news.xs4all.nl 2862 [2001:888:2000:d::a6]:42828 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74370 On Sat, Jul 12, 2014 at 3:07 PM, Alan Bawden wrote: > Steven D'Aprano writes: > >> But perhaps we only care about changes in value, not type. NAN or no NAN, >> list equality works fine: >> >> py> data = [1.0, 2.0, float('nan'), 4.0] >> py> old = data[:] >> py> old == data # No changes made yet, should return True >> True > > You lost me right here. If list equality is determined by comparing > lists element-by-element, and the second element of old is _not_ equal > to the second element of data, then why should old and data be equal? > > In fact, I find myself puzzled about exactly how list equality is > actually defined. In the Python 3 docs, it's made a bit clearer, at least as regards the 'in' and 'not in' operators: it's an identity check followed by an equality check - "x is y or x == y". The same comparison is done for equality, although it's not strictly described there (at least, I couldn't find it). There are a lot of these sorts of corner cases that aren't made really clear in the docs, because the verbosity would be more of a problem than the omission - I consider them to be like "The land continues to burn" on Obsidian Fireheart [1] or the reminder text on Madness [2]; if you go to the Magic: The Gathering Comprehensive Rulebook, you can find the exact "code-accurate" details on how either one works, but that takes several pages of verbiage, and it's much better to just say "you may cast it for its madness cost instead of putting it into your graveyard". For the most part, the identity check is a pure optimization. Most Python objects compare equal to themselves. It only VERY occasionally matters (like when there's a NaN in your list), and for those cases, you have the interactive interpreter to try things at. ChrisA [1] http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=192224 [2] eg http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=118892