Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'value,': 0.04; 'true,': 0.05; 'element': 0.07; '[1,': 0.09; 'false,': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; '~ethan~': 0.09; 'def': 0.12; 'changes': 0.15; 'defined.': 0.16; 'len(other):': 0.16; 'len(self)': 0.16; 'nan': 0.16; 'subject:operators': 0.16; 'elements': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'comparing': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'list:': 0.30; 'alan': 0.31; "d'aprano": 0.31; 'equality': 0.31; 'steven': 0.31; 'writes:': 0.31; 'class': 0.32; 'lists': 0.32; 'equal': 0.35; 'but': 0.35; 'there': 0.35; 'data,': 0.36; 'false': 0.36; 'charset :us-ascii': 0.36; 'should': 0.36; 'list': 0.37; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'break': 0.61; 'lost': 0.61; 'received:173': 0.61; 'myself': 0.63; 'fact,': 0.69; 'received:gateway02.websitewelcome.com': 0.91; 'subject:Proposal': 0.91 Date: Fri, 11 Jul 2014 23:11:37 -0700 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Proposal: === and !=== operators References: <53bce8a3$0$2746$c3e8da3$76491128@news.astraweb.com> <53c0abe8$0$9505$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3304.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source-IP: 173.12.184.233 X-Exim-ID: 1X5qX2-0005wh-Oq X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([173.12.184.233]) [173.12.184.233]:38905 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 1 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3IzMzA0Lmhvc3RnYXRvci5jb20= 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: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1405146988 news.xs4all.nl 2929 [2001:888:2000:d::a6]:37337 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74373 On 07/11/2014 10: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. Consider: > > >>> a = float('nan') > >>> x = [1, a, 9] > >>> y = [1, a, 9.0] > >>> x == y > True > > So is there some equality predicate where corresponding elements of x > and y are equal? > > >>> map(operator.eq, x, y) > [True, False, True] > > It's not "==". > > >>> map(operator.is_, x, y) > [True, True, False] > > And it's not "is". class list: def __eq__(self, other): if len(self) != len(other): return False for this, that in zip(self, other): if this is that or this == that: continue break else: return True return False -- ~Ethan~