IndexError: " pop index out of range" with a for loop
<p>Goodmorning,
I just wrote this program in python and this <code>IndexError</code> keeps showing up. I don't know how to resolve it, I even tried by using a while loop but nothing changed...I hope someone can help me with this problem!</p>

<p>Here is my code, it should check the length of the object of two lists (la, lb) and: remove the string from the la list  if the string is less long than the lb 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>

<p>Try with that:</p>

<pre><code>def rmv(la,lb):
    for i in range(len(la)):
        if len(la[i])&lt;len(lb[i]):
            la[i]=None
        elif len(la[i])&gt;len(lb[i]):
            lb[i]=None
        else:
            la[i]=lb[i]=None    
    la = [i for i in la if i is not None]
    lb = [i for i in lb if i is not None]
    return (la,lb)
</code></pre>

<p>Example:</p>

<pre><code>la = ['ant','string1','panda']
lb = ['elephant','string','panda']
lists = rmv(la,lb)
print lists[0]
print lists[1]
</code></pre>

<p>Result:</p>

<pre><code>['string1']
['elephant']
</code></pre>

python