index error with lists while using del, cant figure it out
<p>I am new to programming so this code is probable fairly junky. Anyhow what i am trying to do is take two lists(xy1,xy2), which hold the corners of a rectangle and see if they overlap with other rectangles. The format i used for it is x1,y1 are in array xy1 and x2,y2 are in array xy2. So far i am only working with the x axis so every other entry in both of the arrays. My problem is that when i find the ones that are overlapping and delete them i get an index error. I believe the problem is something to do with using del and my for loops max which i get using the len of the array. The code also works sometimes if nothing overlaps and triggers the removed calls. Any suggestions are appreciated. Thanks</p>

<pre><code>#1,3 are x cords for first rect, 5 and 8 are x cords for second rect
xy1=[1,6,5,12,1,17]
xy2=[3,9,8,16,4,19]
def make(xy1,xy2):
    count0=0
    for count1 in range(count0,len(xy1),2):
        for count2 in range(count0,len(xy2),2):
            if xy1[count1] in range(xy1[count2],xy2[count2]) and not (count1==count2):
                xy1=removed(xy1,count1)
                xy2=removed(xy2,count1)
    return xy1,xy2

def removed(xy1,count1):
    #removes the x,y that was overlapped along with the other 2 corners of the rect
    del xy1[count1:count1+2]
    return xy1

make(xy1,xy2)

print xy1,xy2
</code></pre>
