How to get top of keys from dict by values?
<p>I have dictionary:</p>

<pre><code>{ "key1" : 1, "key2" : 2, ...., "key100" : 100 }
</code></pre>

<p>I want to get list top5 keys by sort values from this dictionary:</p>

<pre><code>[ "key100", "key99",.. "key95" ]
</code></pre>

<p>How to do it ?</p>

<p>Just sort keys using lambda function to return value as key, reversed, and take the 5 first values:</p>

<pre><code>d={ "key1" : 1, "key2" : 2, "key3" : 3, "key200" : 200 , "key100" : 100 , "key400" : 400}


print(sorted(d.keys(),reverse=True,key=lambda x : d[x] )[:5])
</code></pre>

<p>output:</p>

<pre><code>['key400', 'key200', 'key100', 'key3', 'key2']
</code></pre>

python