Message92908
| 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)) |
|