Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: how to convert code that uses cmp to python3 Date: Fri, 8 Apr 2016 11:05:43 -0600 Lines: 27 Message-ID: References: <57064D0D.1030701@rece.vub.ac.be> <87r3egfqiv.fsf@elektro.pacujo.net> <570778ad$0$1587$c3e8da3$5496439d@news.astraweb.com> <87d1q0giwd.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de Csqfm3Ub36SrFHz+Bl3NDAylrBO4onpNq+q3CzkChLEw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'elif': 0.04; 'granted,': 0.07; 'subject:code': 0.07; 'incorrect': 0.09; 'skip:= 70': 0.10; '*should*': 0.16; '2016': 0.16; 'comparisons,': 0.16; 'key:': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:python3': 0.16; 'worst': 0.16; 'wrote:': 0.16; 'tree': 0.18; 'issue.': 0.20; 'assumes': 0.22; 'explicit': 0.22; 'keys': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'fine': 0.28; 'equality': 0.29; 'node': 0.29; 'subject:that': 0.29; 'operations': 0.31; 'probably': 0.31; 'ordered': 0.33; 'point,': 0.33; 'structure': 0.34; 'received:google.com': 0.35; 'could': 0.35; "isn't": 0.35; 'but': 0.36; 'received:209.85': 0.36; 'totally': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'two': 0.37; 'being': 0.37; 'received:209.85.213': 0.37; 'doing': 0.38; 'received:209': 0.38; 'data': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'more': 0.63; 'present.': 0.72; 'insert,': 0.84; 'needed:': 0.84; "op's": 0.84; 'to:name:python': 0.84; 'contextual': 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; bh=urb+Z47b+6TtObzzTMwsAaR0kI6EAIAE4efV/rGhCBg=; b=j16vr2QsFKABUFyX7YxoaJsSCN4APXqbigo40L5/dQgpFDA14usyJqVzh3BtxESPwM +wE4EiLWtuCuhZvwIzTOEMMMZqBqs1hYSCXfRyRH3piEatzSe987GsA+EfwWP3RB4HEH fSIzzVqLeqC8Wmiy/lX7S06KHj+PbX1o2fYRBBkr0Km0F3iho4Yo24vUzZJ4RD61eo7E qFRCBsSjU61tAoHUucw2lHPzZnO3r1VYd0eVVM6kscUq41XRHl0DivaUALNnsQew0lb1 36jRJq2D1HMeiQxWLCgjWkx9j601VVA4lmStK5PPoyVCa8y5x3+4wp52FygM3vljYw6v TIxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=urb+Z47b+6TtObzzTMwsAaR0kI6EAIAE4efV/rGhCBg=; b=NBS6HcQhQLefgBUiMaRMduxKwHQSz6Cx0xSVzZC4PvQs9kpYee0ib4QPH44Yjx02J4 AQcH4vYgU7LfrlOVo6f1gxZBU8QSIp8xd3ZE/EFSkNHCRHTz34iLiZx+keSxn+Lb++eZ M+ftWjJ6ep6tpkPVA+6mQCzW358RWr0WcyOsuqMm1iGhvw5quhLdLsSsc7Z1XmZvjjC0 Hywwj/KODTpceKBzCuutSmBCqhYnIvfcPC31lfc5pJPaH8u0mtqJOKZbh3DdnvKgzuj+ Pb8SH2ZhX5QU7s1RWNTRrFQoUEnrePaUMIrVPUmsK6inDT2TKjwUQQxrz9le5wotUe0E MMCA== X-Gm-Message-State: AD7BkJIGiTGOFnz31LqhtaaCYpjZJOVmkHL7edIrpdaux5DHWlOmp3+Kj63jpksYfSFBo8hegogcfJH/tLPZnA== X-Received: by 10.50.13.36 with SMTP id e4mr4964457igc.85.1460135183576; Fri, 08 Apr 2016 10:06:23 -0700 (PDT) In-Reply-To: <87d1q0giwd.fsf@elektro.pacujo.net> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <57064D0D.1030701@rece.vub.ac.be> <87r3egfqiv.fsf@elektro.pacujo.net> <570778ad$0$1587$c3e8da3$5496439d@news.astraweb.com> <87d1q0giwd.fsf@elektro.pacujo.net> Xref: csiph.com comp.lang.python:106693 On Fri, Apr 8, 2016 at 10:33 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> That's fine for those operations and probably insert, but how do you >> search an AVL tree for a specific key without also using __eq__? > > Not needed: > > ======================================================================== > if key < node.key: > look_right() > elif node.key < key: > look_left() > else: > found_it() > ======================================================================== That makes me a little nervous since it assumes that the keys are totally ordered and could return an incorrect node if they aren't. Granted, the keys *should* be totally ordered if the data structure is being used properly, but an explicit equality check ensures that the worst that could happen is the node simply isn't found despite being present. More to the contextual point, this is still doing two comparisons, even if both of them are less than, so it doesn't really solve the OP's issue.