how to convert code that uses cmp to python3

Antoon Pardon antoon.pardon at rece.vub.ac.be
Thu Apr 7 08:05:33 EDT 2016


I am looking at my avltree module for converting it to
python3.

One of the things that trouble me here is how python3 no
longer has cmp and how things have to be of "compatible"
type in order to be comparable.

So in python2 it wasn't a problem to have a tree with
numbers and strings as keys. In python3 that will not
be so evident.

In python2 descending the tree would only involve at
most one expensive comparison, because using cmp would
codify that comparison into an integer which would then
be cheap to compare with 0. Now in python3, I may need
to do two expensive comparisons, because there is no
__cmp__ method, to make such a codefication.

Is there a way to work around these limitations or
should I resign myself to working within them?

-- 
Antoon Pardon



More information about the Python-list mailing list