IndexError: "pop index out of range" with a for loop
<p>How can I resolve this <code>IndexError</code>? I tried by using a <code>while</code> loop, but nothing changed.</p>
<p>Here is my code, it should check the length of the object of two lists (<code>la</code>, <code>lb</code>) and remove the string from <code>la</code> if the string is shorter than the <code>lb</code> string and vice versa. Plus it has to remove both of the strings if their length is the same.</p>
<pre><code>def change(l1, l2):
    la1 = l1[:]
    la2 = l2[:]
    i = 0
    for i in range(len(la1)): 
        if la1[i] == la2[i]:
            l1.pop(i)
            l2.pop(i)
        elif la1[i] &gt; la2[i]:
            l2.pop(i)
        elif la2[i] &gt; la1[i]:
            l1.pop(i)
</code></pre>