List out of index after deleting elements- python
<p>I'm trying to implement a simple SSTF program and trying to iterate over the queue of processes that have come in and subsequently delete anything that I have taken into account but it says "Out of index error".</p>

<pre><code>for i in xrange(0,len(queue)):
    for j in xrange(0,(len(queue))):
        a = abs(queue[j]-initial_position)
        if(min&gt;a):
            min = a
            pos = j

initial_position=queue[pos]

final_queue.append(initial_position)
del(queue[pos])
</code></pre>

<p>The complete error message: </p>

<pre><code>initial_position=queue[pos]
IndexError: list index out of range
</code></pre>

<p>I'm really confused.</p>

<p>My guess is that you didn't initialize min and pos properly (e.g. min is not small enough), thus the value pos has never been set. Then queue[pos] points to an undefined position.</p>

python algorithm python-2.7