Message92908
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)) |
|
Date |
User |
Action |
Args |
2009-09-20 17:39:51 | aronacher | set | recipients:
+ aronacher, georg.brandl, rhettinger, belopolsky, pitrou, idadesub, erickt, robert.kern |
2009-09-20 17:39:51 | aronacher | set | messageid: <1253468391.68.0.469077199633.issue3976@psf.upfronthosting.co.za> |
2009-09-20 17:39:50 | aronacher | link | issue3976 messages |
2009-09-20 17:39:50 | aronacher | create | |
|