Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106686
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: how to convert code that uses cmp to python3 |
| Date | Sat, 9 Apr 2016 00:25:26 +1000 |
| Lines | 25 |
| Message-ID | <mailman.89.1460125529.2253.python-list@python.org> (permalink) |
| References | <57064D0D.1030701@rece.vub.ac.be> <CAPTjJmrGiQS9uhFU-+TQ4nUWQ2p4gmJoQitMotS0Ob--qm1iWg@mail.gmail.com> <5706C961.2000009@rece.vub.ac.be> <CAPTjJmrbL870mV1kU8nHar=bPyKZRmhKP-8iUs_tpYVo5vhhOA@mail.gmail.com> <57075F43.7060004@rece.vub.ac.be> <85fuuw5ypl.fsf@benfinney.id.au> <5707B2CE.1010407@rece.vub.ac.be> <CAPTjJmrMv5O5vwrbfHJJCdiHi87naPOanhPmk4Ba_SLRgu1m4Q@mail.gmail.com> <5707BE18.1050805@rece.vub.ac.be> <CAPTjJmoMuqwg0Q_fp=qitC3wWkXYHtdqBNVGzO+3ToAmsgit8Q@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de ZlypCVuxlo5/svERG+UHFg4aGJjjH+0kioXxBnn+BwOA== |
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'subject:code': 0.07; 'cc:addr:python-list': 0.09; 'python': 0.10; 'argument': 0.15; '2016': 0.16; 'cheaper.': 0.16; 'comparisons,': 0.16; 'equal.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'node.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:python3': 0.16; 'traverse': 0.16; 'wrote:': 0.16; 'exists': 0.18; 'tree': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'otherwise,': 0.20; 'stopping': 0.22; 'am,': 0.23; 'sat,': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'compare': 0.27; 'right.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'comparison': 0.29; 'key,': 0.29; 'node': 0.29; 'subject:that': 0.29; 'objects': 0.29; 'version,': 0.30; "can't": 0.32; 'handle': 0.34; 'received:google.com': 0.35; 'something': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'smaller': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'two': 0.37; 'received:209': 0.38; 'rather': 0.39; 'your': 0.60; 'it!': 0.64; '50%': 0.79; '12:20': 0.84; 'chrisa': 0.84; 'pardon': 0.84; 'to:none': 0.91 |
| 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; bh=9p6NfFb99boQ1955YJdwldEANY9I8wGCXijoPCdH9r0=; b=lKvbo8hylt0/9iVE/laZTPeaC0UjfzExVFQuWF0H7FG8GsWWsyNmMUI7f2WO0TudDW D7b0kFT8JHHZCy2VHiHKZGSsivZfcOV17cAXc1R2cvrTNEIR5UmF99FujS+r6FtwE+DH bUsNcTvz/uMf2qZVhhl5GT4H+MA9/YLnAJUoD0NUyjWGkg7PzDrDNg1rrNnJZgq2dQNJ 5XwhfBIzaFOIzpKmGY+75hf++Lo5jt4MJAWGlpDpRYHtn8WOFTMZi9lWucdhbRcEu5IZ zBMVgj8RIeBAgA3455qfmg9y2LFA3fnLiJGD+fq21MvqdmMNx5BiQpm58tQN5za5zA1n VYIQ== |
| 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:date :message-id:subject:from:cc; bh=9p6NfFb99boQ1955YJdwldEANY9I8wGCXijoPCdH9r0=; b=LsuKIeV8BN2moUyXOjgnuWUxDnMFxZBqMYSmsOAtzOP9arGkEdhKAnRfXDCO1FYvSS kajf5Z7jB3b3q7B3sAOAaZ2Bc5+LeO058Micchhc7Nxaf5yN4jErGTvr8vhsxEKcziy4 BbUtSUPW6mg/ycDm3Iz+xV+VwPbFZNjFLN78rSN5iLQSwDz1Pijjc4o+Rwt3GymAsmcb /bjE5oxrWHXbZjla+b1SskXslQIkvtNxnjx8Le3yr1KPZDCxLerDBoHEs3aNfqFL/Rfo ciAD108P6QA/CMMw+eqWjEg++Ut+tNPeoXY8T3tAZ0EwUt+u6eHBwshPLP9ViIKhlrSG IXmg== |
| X-Gm-Message-State | AD7BkJKWbH/i/Ym0BZlDkCpwqojmj+y4fW/gk9BqubzllJQ7keCuvIXToGhNCzqQ0xYZXNgcPjyGyWnNEd1zWQ== |
| X-Received | by 10.107.169.32 with SMTP id s32mr8981089ioe.19.1460125526809; Fri, 08 Apr 2016 07:25:26 -0700 (PDT) |
| In-Reply-To | <5707BE18.1050805@rece.vub.ac.be> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <CAPTjJmoMuqwg0Q_fp=qitC3wWkXYHtdqBNVGzO+3ToAmsgit8Q@mail.gmail.com> |
| X-Mailman-Original-References | <57064D0D.1030701@rece.vub.ac.be> <CAPTjJmrGiQS9uhFU-+TQ4nUWQ2p4gmJoQitMotS0Ob--qm1iWg@mail.gmail.com> <5706C961.2000009@rece.vub.ac.be> <CAPTjJmrbL870mV1kU8nHar=bPyKZRmhKP-8iUs_tpYVo5vhhOA@mail.gmail.com> <57075F43.7060004@rece.vub.ac.be> <85fuuw5ypl.fsf@benfinney.id.au> <5707B2CE.1010407@rece.vub.ac.be> <CAPTjJmrMv5O5vwrbfHJJCdiHi87naPOanhPmk4Ba_SLRgu1m4Q@mail.gmail.com> <5707BE18.1050805@rece.vub.ac.be> |
| Xref | csiph.com comp.lang.python:106686 |
Show key headers only | View raw
On Sat, Apr 9, 2016 at 12:20 AM, Antoon Pardon <antoon.pardon@rece.vub.ac.be> wrote: >> You only need ONE comparison, and the other is presumed to be its >> opposite. When, in the Python 3 version, would you need to compare >> twice? > > About 50% of the time. When I traverse the tree I go left when the > argument key is smaller than the node key, I go right when it is > greater than the node key and I have found the node I want when > they are equal. How about this: You have found the node if they are equal. Otherwise, go left if your argument is smaller than the node. Otherwise, go right. You don't have to do three comparisons, only two - and one of them is an equality, rather than an inequality, which is often cheaper. But hey. If you really can't handle the double comparison, *write your own* special-purpose comparison function - nobody's stopping you! It's just not something that exists *in the language*. If your specific objects need this, write it! ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: how to convert code that uses cmp to python3 Chris Angelico <rosuav@gmail.com> - 2016-04-09 00:25 +1000
csiph-web