| Conditions | 1 | 
| Total Lines | 29 | 
| Code Lines | 17 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- | ||
| 5 | def cmp_to_key(mycmp): | ||
| 6 | """ | ||
| 7 | List sort related function | ||
| 8 | |||
| 9 | Convert a cmp= function into a key= function | ||
| 10 | """ | ||
| 11 | class K(object): | ||
| 12 | def __init__(self, obj, *args): | ||
| 13 | self.obj = obj | ||
| 14 | |||
| 15 | def __lt__(self, other): | ||
| 16 | return mycmp(self.obj, other.obj) < 0 | ||
| 17 | |||
| 18 | def __gt__(self, other): | ||
| 19 | return mycmp(self.obj, other.obj) > 0 | ||
| 20 | |||
| 21 | def __eq__(self, other): | ||
| 22 | return mycmp(self.obj, other.obj) == 0 | ||
| 23 | |||
| 24 | def __le__(self, other): | ||
| 25 | return mycmp(self.obj, other.obj) <= 0 | ||
| 26 | |||
| 27 | def __ge__(self, other): | ||
| 28 | return mycmp(self.obj, other.obj) >= 0 | ||
| 29 | |||
| 30 | def __ne__(self, other): | ||
| 31 | return mycmp(self.obj, other.obj) != 0 | ||
| 32 | |||
| 33 | return K | ||
| 34 | |||
| 46 | 
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.