[Tutor] samples on sort method of sequence object.

Hugo Arts hugo.yoshi at gmail.com
Thu Jan 14 10:22:05 CET 2010


On Thu, Jan 14, 2010 at 10:13 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:
>
> Note that this won't work in Py3, where the "cmp" parameter is gone.
>
> Stefan

And he's right again. I should've checked for that. Well, that makes a
CmpInt class the only other solution:

class CmpInt(int):
    def __lt__(self, other):
        if isinstance(other, str): return True
        return int.__lt__(self, other)
    def __gt__(self, other):
        if isinstance(other, str): return False
        return int.__gt__(self, other)

Hugo


More information about the Tutor mailing list