title: How to reduce a collection of ranges to a minimal set of ranges
body: <p>I'm trying to remove overlapping values from a collection of ranges.</p>
  
  <p>The ranges are represented by a string like this:</p>
  
  <p><code>499-505 100-115 80-119 113-140 500-550</code></p>
  
  <p>I want the above to be reduced to two ranges: <code>80-140 499-550</code>. That covers all the values without overlap.</p>
  
  <p>Currently I have the following code.</p>
  
  <pre><code>cr = "100-115 115-119 113-125 80-114 180-185 500-550 109-120 95-114 200-250".split(" ")
  ar = []
  br = []
  
  for i in cr:
      (left,right) = i.split("-")
      ar.append(left);
      br.append(right);
  
  inc = 0
  for f in br:    
  
      i = int(f)
      vac = []
      jnc = 0
      for g in ar:
          j = int(g)  
          if(i &gt;= j):
              vac.append(j)
              del br[jnc]
              jnc += jnc 
  
      print vac 
      inc += inc
  </code></pre>
  
  <p>I split the array by <code>-</code> and store the range limits in <code>ar</code> and <code>br</code>. I iterate over these limits pairwise and if the <code>i</code> is at least as great as the <code>j</code>, I want to delete the element. But the program doesn't work. I expect it to produce this result: <code>80-125 500-550 200-250 180-185</code></p>