how to convert code that uses cmp to python3
Ben Finney
ben+python at benfinney.id.au
Thu Apr 7 17:08:35 EDT 2016
Antoon Pardon <antoon.pardon at rece.vub.ac.be> writes:
> With this method I have to traverse the two tuples almost always
> twice. Once to find out if they are equal and if not a second time to
> find out which is greater.
You are essentially describing the new internal API of comparison
operators. That's pretty much unavoidable.
If you want to avoid repeating an expensive operation – the computation
of the comparison value for an object – you could add an LRU cache to
that function. See ‘functools.lru_cache’.
--
\ “He that would make his own liberty secure must guard even his |
`\ enemy from oppression.” —Thomas Paine |
_o__) |
Ben Finney
More information about the Python-list
mailing list