lambda python function in reversing list
<pre><code>scores = []
with open("scores.txt") as f:
    for line in f:
        name, score = line.split(',')
        score = int(score)
        scores.append((name, score))
        scores.sort(key=lambda s: s[1])
for name, score in scores:
    print(name + ", " + str(score))
</code></pre>

<p>This code can be used to show a txt file looking like this (disordered):</p>

<pre><code>alpha, 3
beta, 1
gamma, 2
</code></pre>

<p>To looking like this:</p>

<pre><code>beta, 1
gamma, 2
alpha, 3
</code></pre>

<p>How can I modify the code so that it instead prints as:</p>

<pre><code>alpha, 3
gamma, 2
beta, 1 
</code></pre>

<p>Use <code>reverse</code> when you sort:  </p>

<pre><code>&gt;&gt;&gt; l  = [('a', 1), ('c',5), ('a', 2), ('b', 1)]
&gt;&gt;&gt; l.sort(key=lambda i: i[1], reverse=True)
&gt;&gt;&gt; l
[('c', 5), ('a', 2), ('a', 1), ('b', 1)]
</code></pre>

<p>You can use it with <code>sorted</code>:  </p>

<pre><code>&gt;&gt;&gt; l  = [('a', 1), ('c',5), ('a', 2), ('b', 1)]
&gt;&gt;&gt; sorted(l, key=lambda i: i[1], reverse=True)
[('c', 5), ('a', 2), ('a', 1), ('b', 1)]
&gt;&gt;&gt; 
</code></pre>

python