This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author aronacher
Recipients aronacher, belopolsky, erickt, georg.brandl, idadesub, pitrou, rhettinger, robert.kern
Date 2009-09-20.17:39:50
SpamBayes Score 6.8149293e-06
Marked as misclassified No
Message-id <1253468391.68.0.469077199633.issue3976@psf.upfronthosting.co.za>
In-reply-to
Content
Eg, something like this:

class safe_key(object):

    __slots__ = ('obj',)

    def __init__(self, obj):
        self.obj = obj

    def __eq__(self, other):
        return self.obj.__eq__(other.obj)

    def __lt__(self, other):
        rv = self.obj.__lt__(other.obj)
        if rv is NotImplemented:
            rv = id(type(self.obj)) < id(type(other.obj))
        return rv


ls = [2, 1, 1.0, 1.5, 'a', 'c', 'b']
print(sorted(ls, key=safe_key))
History
Date User Action Args
2009-09-20 17:39:51aronachersetrecipients: + aronacher, georg.brandl, rhettinger, belopolsky, pitrou, idadesub, erickt, robert.kern
2009-09-20 17:39:51aronachersetmessageid: <1253468391.68.0.469077199633.issue3976@psf.upfronthosting.co.za>
2009-09-20 17:39:50aronacherlinkissue3976 messages
2009-09-20 17:39:50aronachercreate