Forward port total_ordering() and cmp_to_key().

This commit is contained in:
Raymond Hettinger 2010-04-05 18:56:31 +00:00
parent 5daab45158
commit c50846aaef
10 changed files with 186 additions and 25 deletions

View file

@ -70,15 +70,6 @@ def unorderable_list_difference(expected, actual):
# anything left in actual is unexpected
return missing, actual
def CmpToKey(mycmp):
'Convert a cmp= function into a key= function'
class K(object):
def __init__(self, obj, *args):
self.obj = obj
def __lt__(self, other):
return mycmp(self.obj, other.obj) == -1
return K
def three_way_cmp(x, y):
"""Return -1 if x < y, 0 if x == y and 1 if x > y"""
return (x > y) - (x < y)