Message92906
OK, there *is* a way. Consider 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):
try:
return self.obj < other.obj
except TypeError:
return id(type(self.obj)) < id(type(other.obj))
ls = [2, 1, 1.0, 1.5, 'a', 'c', 'b']
print(sorted(ls, key=safe_key)) |
|
Date |
User |
Action |
Args |
2009-09-20 17:35:08 | georg.brandl | set | recipients:
+ georg.brandl, rhettinger, belopolsky, pitrou, idadesub, erickt, aronacher, robert.kern |
2009-09-20 17:35:08 | georg.brandl | set | messageid: <1253468108.76.0.978596738678.issue3976@psf.upfronthosting.co.za> |
2009-09-20 17:35:07 | georg.brandl | link | issue3976 messages |
2009-09-20 17:35:07 | georg.brandl | create | |
|