Number set type

Justin Azoff justin.azoff at gmail.com
Thu Dec 29 02:26:33 EST 2005


Justin  Azoff wrote:
> Yes.. if they are sorted, something like this should work:
Oops, that was almost right, but it would skip some ranges.

This should always work:

...
        while 1:
            try :
                if a.intersects(b):
                    ret.append(a.intersection(b))
                    if a.end < b.end:
                        a = ai.next()
                    else :
                        b = bi.next()
                elif a.start < b.start:
                    a = ai.next()
                else :
                    b = bi.next()
            except StopIteration:
                break
        return RangeList(ret)



-- 
- Justin




More information about the Python-list mailing list