mirror of
https://github.com/python/cpython.git
synced 2025-08-27 20:25:18 +00:00
Forward port total_ordering() and cmp_to_key().
This commit is contained in:
parent
5daab45158
commit
c50846aaef
10 changed files with 186 additions and 25 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue