I simply want to sort a list... and I have a 2 parameter lambda Here is my simple code:
I.sort(key = lambda x, y: x.finish - y.finish)
And the compiler return this error
builtins.TypeError: <lambda>() missing 1 required positional argument: 'y'
You are trying to use key function as a cmp function (removed in Python 3.x), but don't you mean to simply sort by the "finish" attribute:
I.sort(key=lambda x: x.finish)
Or, with the "attrgetter":
from operator import attrgetter
I.sort(key=attrgetter("finish"))
cmpandkeyarguments;cmpis entirely gone from Python 3. Forkey, just usekey=lambda x: x.finish