Sorting based on max length and max sum
<p>Can you please help me figure this out</p>

<pre><code>q = [[12, 13, 14], [8, 9, 10,11], [2, 3, 4], [5, 6, 7]]
</code></pre>

<p>suppose I've a list like q, How do I sort the based on </p>

<ol>
<li>Max length of sublists and  </li>
<li>Max sum of the sublists</li>
</ol>

<p>The output should be:</p>

<pre><code>q = [[8,9,10,11],[12,13,14][5,6,7],[1,2,3]]
</code></pre>

<p>Supply your criteria in a lambda function for the <code>key</code>:</p>

<pre><code>sorted(q, key=lambda sub: (len(sub), sum(sub)), reverse=True)
&gt;&gt;&gt; [[8, 9, 10, 11], [12, 13, 14], [5, 6, 7], [2, 3, 4]]
</code></pre>

<p>The <code>lambda</code> function will take every sub-list <code>x</code> and sort it based on it's <code>len</code>, in cases where the result of <code>len</code> is not sufficient in making a decision, the <code>sum</code> of their contents is used to break the tie.</p>

python list sorting