MCPcopy Index your code
hub / github.com/python/cpython / cmp_to_key

Function cmp_to_key

Lib/functools.py:206–223  ·  view source on GitHub ↗

Convert a cmp= function into a key= function

(mycmp)

Source from the content-addressed store, hash-verified

204################################################################################
205
206def 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
225try:
226 from _functools import cmp_to_key

Callers 8

sort_statsMethod · 0.90
checkFunction · 0.90
testStressfullyMethod · 0.90
test_decoratedMethod · 0.90
test_sortMethod · 0.90

Calls

no outgoing calls

Tested by 7

checkFunction · 0.72
testStressfullyMethod · 0.72
test_decoratedMethod · 0.72
test_sortMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…