Python - find highest dictionary key with value greater than zero
<p>I have a dictionary</p>

<pre><code>{0: 12, 1: 1, 2: 13, 3: 7, 4: 0}
</code></pre>

<p>I want to find the highest dictionary key with a value greater than 0.</p>

<p>In this case, the answer is 3.</p>

<p>What's the best way to do this?</p>

<p>You can use <code>max</code> and <code>dict.items()</code> to do this:</p>

<pre><code>d = {0: 12, 1: 1, 2: 13, 3: 7, 4: 0}

highest = max(i for i,j in d.items() if j &gt; 0)
</code></pre>

python dictionary