title: Python "R Cut" function
body: <p>I am wondering if there is a function in Python already written for the goal that I describe later. If not, what would be the easiest way to implement. My code is attached. </p>
  
  <p>Say I have a range from 1 to 999999999. Given a list of numbers like this:</p>
  
  <pre><code>[9, 44, 99]
  </code></pre>
  
  <p>It would return </p>
  
  <pre><code>[(1,9), (10,44), (45,99), (100, 999999999)]
  </code></pre>
  
  <p>If the number which are the limits are included in the input numbers, it should handle that also. 
  Say input is </p>
  
  <pre><code>[1, 9, 44, 999999999]
  </code></pre>
  
  <p>The return should be:</p>
  
  <pre><code>[(1,9), (10,44), (45, 999999999)]
  </code></pre>
  
  <p>I could write a for loop comparing with a few conditional statement but wondering if there is a more 'smart way'. </p>
  
  <p>Some data massage that might be helpful:</p>
  
  <pre><code>points = [1, 9, 44, 99]
  points = sorted(list(set(points + [1, 999999999])))
  </code></pre>
  
  <p><em><strong>UPDATED INFO:
  FINAL CREDITS GIVEN TO alecxe, thanks for your inspiring list comprehension solution</em></strong></p>
  
  <pre><code>l = sorted(list(set(points + [1, 999999999])))
  [(l[i] + int(i != 0), l[i + 1]) for i in xrange(len(l) - 1)]
  </code></pre>
  
  <p>You can put all that in one line but I think that is unnessary.</p>