python function slowing down for no apparent reason
<p>I have a python function defined as follows which i use to delete from list1 the items which are already in list2. I am using python 2.6.2 on windows XP</p>

<pre><code>def compareLists(list1, list2):
    curIndex = 0
    while curIndex &lt; len(list1):
        if list1[curIndex] in list2:
            list1.pop(curIndex)
        else:
            curIndex += 1
</code></pre>

<p>Here, list1 and list2 are a list of lists </p>

<pre><code>list1 = [ ['a', 11221, '2232'], ['b', 1321, '22342'] .. ]

# list2 has a similar format.
</code></pre>

<p>I tried this function with list1 with 38,000 elements and list2 with 150,000 elements. If i put in a print statement to print the current iteration, I find that the function slows down with each iterations. At first, it processes around 1000 or more items in a second and then after a while it reduces to around 20-50 a second. Why can that be happening? </p>

<p>EDIT: In the case with my data, the curIndex remains 0 or very close to 0 so the pop operation on list1 is almost always on the first item.</p>

<p>If possible, can someone also suggest a better way of doing the same thing in a different way?</p>
