Python error in sorting a list
<p>I simply want to sort a list... and I have a 2 parameter lamda
Here is my simple code:</p>

<pre><code>I.sort(key = lambda x, y: x.finish - y.finish)
</code></pre>

<p>And the compiler return this error</p>

<pre><code>builtins.TypeError: &lt;lambda&gt;() missing 1 required positional argument: 'y'
</code></pre>

<p>You are trying to use <code>key</code> function as a <code>cmp</code> function (removed in Python 3.x), but don't you mean to simply sort by the "finish" attribute:</p>

<pre><code>I.sort(key=lambda x: x.finish)
</code></pre>

<p>Or, with the <a href="https://docs.python.org/3/library/operator.html#operator.attrgetter" rel="nofollow">"attrgetter"</a>:</p>

<pre><code>from operator import attrgetter

I.sort(key=attrgetter("finish"))
</code></pre>

python sorting