how to convert code that uses cmp to python3

Random832 random832 at fastmail.com
Fri Apr 8 10:29:10 EDT 2016


On Fri, Apr 8, 2016, at 10:08, Chris Angelico wrote:
> seq1 == seq2
> seq1 < seq2
> 
> 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?

== might be just as expensive as the others, particularly if the
sequences are unlikely to share object identity. I suspect he chose "s1
< s2; s2 < s1" precisely because someone suggested in another post on
this thread to exclusively use the less-than operator on purity grounds.



More information about the Python-list mailing list