max second element in tuples python
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/4800419/sorting-or-finding-max-value-by-the-second-element-in-a-nested-list-python">Sorting or Finding Max Value by the second element in a nested list. Python</a>  </p>
</blockquote>



<p>I've written a program that gives me a list of tuples. I need to grab the tuple with with the max number in the second value.</p>

<pre><code>    (840, 32), (841, 3), (842, 4), (843, 4), (844, 6), (845, 6), (846, 12), (847, 6), (848, 10), (849, 4), ..snip...
</code></pre>

<p>I need to get back (840,32) because 32 is the highest second number in the tuple. How can I achieve this? I've tried a variety of ways but keep getting stuck here is the complete code:</p>

<pre><code>    D = {}
    def divisor(n):
        global D
        L = []
        for i in range(1,n+1):
        if n % i == 0:
            L.append(i)
            D[n] = len(L)

    for j in range(1001):
        divisor(j)


    print(D.items())
</code></pre>
