title: difference of two sets of intervals
body: <p>i'm trying to write some  code to calculate the difference of two sets of intervals A - B , Interval endpoints are integers , but i'm strugling to come with efficient solution , any suggestion would be much appreciated
  example : [(1, 4), (7, 9)] - [(3,5)] = [(1, 3), (7, 9)]</p>
  
  <p>well this the best i tried so far  ( the two lists are already sorted )</p>
  
  <pre><code>class tp():
     def __repr__(self):
         return '(%.2f,%.2f)' % (self.start, self.end)
     def __init__(self,start,end): 
         self.start=start
         self.end=end
  
  
  
  z=[tp(3,5)] #intervals to be subtracted
  s=[tp(1, 4)),tp(7, 9), tp(3,4),tp(4,6)]
  
  for x in s[:]:
     if z.end &lt; x.start:
      break
     elif z.start &lt; x.start and z.end &gt; x.start and z.end &lt; x.end:
      x.start=z.end
     elif z.start &lt; x.start and z.end &gt; x.end:
      s.remove(x)
     elif z.start &gt; x.start and z.end &lt; x.end:
      s.append(tp(x.start,z.start))
      s.append(tp(z.end,x.end))
      s.remove(x)
     elif z.start &gt; x.start and z.start &lt; x.end and z.end &gt; x.end:
      x.end=z.start
     elif z.start &gt; x.end:
      continue
  </code></pre>