homepage

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 georg.brandl
Recipients aronacher, belopolsky, erickt, georg.brandl, idadesub, pitrou, rhettinger, robert.kern
Date 2009年09月20日.17:35:07
SpamBayes Score 2.5030164e-07
Marked as misclassified No
Message-id <1253468108.76.0.978596738678.issue3976@psf.upfronthosting.co.za>
In-reply-to
Content
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))
History
Date User Action Args
2009年09月20日 17:35:08georg.brandlsetrecipients: + georg.brandl, rhettinger, belopolsky, pitrou, idadesub, erickt, aronacher, robert.kern
2009年09月20日 17:35:08georg.brandlsetmessageid: <1253468108.76.0.978596738678.issue3976@psf.upfronthosting.co.za>
2009年09月20日 17:35:07georg.brandllinkissue3976 messages
2009年09月20日 17:35:07georg.brandlcreate

AltStyle によって変換されたページ (->オリジナル) /