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>

<pre><code>d = { "key1" : 1, "key2" : 2, ...., "key100" : 100 }
a = sorted(d.values())
a.reverse()
req_list = []
for i in a[:5]:
    req_list.append(d.keys()[d.values().index(i)])

print req_list
</code></pre>

<p>This would give you the list with greatest 5 values. Is this what you wanted?</p>

python