Sorting a Two Dimensional List in python using Insertion Sort
<p>So I want to sort a list of namedtuples using insertion sort in python, and here is my code.</p>

<pre><code>    def sortIt(tripods):
        for i in range(1, len(tripods)):
            tmp = tripods[i][3]
            k = i
            while k &gt; 0 and tmp &lt; tripods[k - 1][3]:
                tripods[k] = tripods[k - 1]
                k -= 1
            tripods[k] = tmp
</code></pre>

<p>Whenever it runs it gives me a TypeError: int object is not suscriptable.
Tripods is a list of namedTuples and the index 3 of the namedTuple is what I want the list to be ordered by.  </p>

<pre><code>def sortIt(tripods):
    for i in range(1, len(tripods)):
        tmp = tripods[i]
        k = i
        while k &gt; 0 and tmp[3] &lt; tripods[k - 1][3]:
            tripods[k] = tripods[k - 1]
            k -= 1
        tripods[k] = tmp
</code></pre>

<p>I have modified your code. You were assigning <code>tripods[i][3]</code> to tmp, which is a <code>int</code>. That's why the compiler warns you <code>int</code> is not suscriptable.</p>

python list sorting