Confusion with comparison error
<p>When i run the following </p>

<pre class="lang-python prettyprint-override"><code>def max(L):
    m = L[0][0]
    for item in L:
        if item[0] &gt; m:
            m = item
    return m

L = [[20, 10], [10, 20], [30, 20],[12,16]]
print(max(L))
</code></pre>

<p>i get the error 
 <code>TypeError: unorderable types: int() &gt; list()</code> at line 4. The confusion comes when i try to get the <code>len()</code> of both members. So from the error message it's reasonable to assume <code>m</code> is the list so i run </p>

<pre class="lang-python prettyprint-override"><code>def max(L):
    m = L[0][0]
    for item in L:
        len(m)
        if item[0] &gt; m:
            m = item
    return m

L = [[20, 10], [10, 20], [30, 20],[12,16]]
print(max(L))
</code></pre>

<p>and get the error <code>len(m) TypeError: object of type 'int' has no len()</code>. Ok so the only option left is that <code>item[0]</code> is the list... so similarly </p>

<pre class="lang-python prettyprint-override"><code>def max(L):
    m = L[0][0]
    for item in L:
        len(item[0])
        if item[0] &gt; m:
            m = item
    return m

L = [[20, 10], [10, 20], [30, 20],[12,16]]
print(max(L))
</code></pre>

<p>and i get the same error: <code>len(item[0]) TypeError: object of type 'int' has no len()</code>. Since I'm somewhat certain you can compare 2 ints, I have a hard time understanding what to do about the error originally stated.</p>

<p>In the first iteration of your <em>for</em> loop, doing <code>m = item</code> makes <code>m</code> reference a <code>list</code> which afterwards cannot be compared with an <code>int</code> (viz. <code>item[0] &gt; m</code>) in the next iteration. </p>

<p>You should instead assign <code>m</code> to one of the elements in <code>item</code>, say <code>m = item[0]</code> (to find maximum from first element in each sublist), depending on how exactly you want to compute your maximum value.</p>

<p>On a lighter note, if you're looking for a global maximum, you could simply <a href="http://stackoverflow.com/questions/952914/making-a-flat-list-out-of-list-of-lists-in-python"><em>flatten</em></a> the list and make this easier.</p>

python list int comparison