| 206 | def cmp_to_key(mycmp): |
| 207 | """Convert a cmp= function into a key= function""" |
| 208 | class K(object): |
| 209 | __slots__ = ['obj'] |
| 210 | def __init__(self, obj): |
| 211 | self.obj = obj |
| 212 | def __lt__(self, other): |
| 213 | return mycmp(self.obj, other.obj) < 0 |
| 214 | def __gt__(self, other): |
| 215 | return mycmp(self.obj, other.obj) > 0 |
| 216 | def __eq__(self, other): |
| 217 | return mycmp(self.obj, other.obj) == 0 |
| 218 | def __le__(self, other): |
| 219 | return mycmp(self.obj, other.obj) <= 0 |
| 220 | def __ge__(self, other): |
| 221 | return mycmp(self.obj, other.obj) >= 0 |
| 222 | __hash__ = None |
| 223 | return K |
| 224 | |
| 225 | try: |