how to convert code that uses cmp to python3

Antoon Pardon antoon.pardon at rece.vub.ac.be
Fri Apr 8 10:20:08 EDT 2016


Op 08-04-16 om 16:08 schreef Chris Angelico:
> On Fri, Apr 8, 2016 at 11:31 PM, Antoon Pardon
> <antoon.pardon at 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




More information about the Python-list mailing list