Sorting list of tuples of tuples
<pre><code>[((D,A),0.0),((D,C),0.0),((D,E),0.5)]
</code></pre>

<p>I need to sort the list as:</p>

<pre><code>[((D,E),0.5),((D,A),0.0),((D,C),0.0)]
</code></pre>

<p>I have used the <code>sorted()</code> function and I am able to sort based on values <code>0.5, 0.0</code>... But I am not able to sort on the alphabetical order as I need the list to be sorted in descending order by the numbers and in ascending order of alphabets if the numbers have same value.</p>

<p>Similarly, you could supply <code>sorted</code> with an iterable that is the result of another <code>sort</code>:</p>

<pre><code>&gt;&gt;&gt; from operator import itemgetter
&gt;&gt;&gt; t = [(('D','A'),0.0),(('D','C'),0.0),(('D','E'),0.5)]
&gt;&gt;&gt; sorted(sorted(t), key=itemgetter(1), reverse=True)
[(('D', 'E'), 0.5), (('D', 'A'), 0.0), (('D', 'C'), 0.0)]
</code></pre>

python python-3.x sorting