Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106683 > unrolled thread

Re: how to convert code that uses cmp to python3

Started byAntoon Pardon <antoon.pardon@rece.vub.ac.be>
First post2016-04-08 16:20 +0200
Last post2016-04-08 16:20 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: how to convert code that uses cmp to python3 Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-04-08 16:20 +0200

#106683 — Re: how to convert code that uses cmp to python3

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2016-04-08 16:20 +0200
SubjectRe: how to convert code that uses cmp to python3
Message-ID<mailman.86.1460125230.2253.python-list@python.org>
Op 08-04-16 om 16:08 schreef Chris Angelico:
> On Fri, Apr 8, 2016 at 11:31 PM, Antoon Pardon
> <antoon.pardon@rece.vub.ac.be> wrote:
>> Doing it as follows:
>>     seq1 < seq2
>>     seq2 < seq1
>>
>> takes about 110 seconds.
>>
>>
>> Doing it like this:
>>     delta = cmp(seq1, seq2)
>>     delta < 0
>>     delta > 0
>>
>> takes about 50 seconds.
> Why are you comparing in both directions, though? cmp() is more
> equivalent to this:
>
> seq1 == seq2
> seq1 < seq2

That doesn't make a difference.

> 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.

-- 
Antoon Pardon

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web