Hi,
I have posted an example code to report overlaps between segments in two lists based on their start and end coordinates. The problem is that the while loop is breaking after 'True' and won't iterate through the lists. So, in the example lists it will only return (True, 0, (3015, 3701), 0, (3045, 3800)) and fails to also return other true overlaps in the list (e.g. (100,200) (150,300)).
I have tried introducing for loops at different points, using the itertools etc. but, can't seem to get around it- I know i'm probably missing something silly.
Anyway, thanks for any help!
M
lista = [(3015, 3701), (4011, 5890), (10,40), (150,300)]
listb = [(3045, 3800), (1,2), (100,200), (4500,6000), (20,145)]
def overlap(lista, listb):
a=0
b=0
found=False
while a<len(lista) and b<len(listb):
result=check(lista[a],listb[b])
if result <0:
a +=1
continue
if result > 0:
b +=1
continue
found=True
yield (found, a, lista[a],b,listb[b])
yield found
def check ((astart, aend), (bstart, bend)):
if aend <= bstart:
return -1
if bend <= astart:
return 1
return 0
for a,b in zip(lista,listb):
result1=overlap(lista,listb)
for res in result1:
print res