+ 1
Could you explain how following code would execute and at which line object is created for class and how methods are called ?
def reverse_numeric(x, y): return y - x def cmp_to_key(mycmp): 'Convert a cmp= function into a key= function' class K: def __init__(self, obj, *args): self.obj = obj def __lt__(self, other): return mycmp(self.obj[1], other.obj[1]) < 0 return K print(sorted([[1,2], [2,4], [3,6]], key=cmp_to_key(reverse_numeric)))
1 Respuesta