Python "R Cut" function
Question: 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.

Say I have a range from 1 to 999999999. Given a list of numbers like this:

    
    
    [9, 44, 99]
    

It would return

    
    
    [(1,9), (10,44), (45,99), (100, 999999999)]
    

If the number which are the limits are included in the input numbers, it
should handle that also. Say input is

    
    
    [1, 9, 44, 999999999]
    

The return should be:

    
    
    [(1,9), (10,44), (45, 999999999)]
    

I could write a for loop comparing with a few conditional statement but
wondering if there is a more 'smart way'.

Some data massage that might be helpful:

    
    
    points = [1, 9, 44, 99]
    points = sorted(list(set(points + [1, 999999999])))
    

_**UPDATED INFO: FINAL CREDITS GIVEN TO alecxe, thanks for your inspiring list
comprehension solution_**

    
    
    l = sorted(list(set(points + [1, 999999999])))
    [(l[i] + int(i != 0), l[i + 1]) for i in xrange(len(l) - 1)]
    

You can put all that in one line but I think that is unnessary.


Answer: 
    def myCut(low, high, points):
        answer = []
        curr = low
        for point in points:
            answer.append((curr, point))
            curr = point + 1
        answer.append((curr, high))
        return answer
    
    >>> low = 1
    >>> high = 999999999
    >>> points = [9, 44, 109]
    >>> myCut(low, high, points)
    [(1, 9), (10, 44), (45, 109), (110, 999999999)]
    

Inspired by [this answer](http://stackoverflow.com/a/18538981/198633) and the
discussions that followed, here's a solution in fewer lines, with `itertools`.
This uses `itertools.chain` and `itertools.izip` (in python2.7; `zip` in
python3.x) to reduce the time and space complexities arising from adding
lists, sorting and setifying. Note that the solution assumes that the input
list is already sorted, failing which, erroneous results will be produced

    
    
    cuts = [(i+1, j) for i,j in itertools.izip(itertools.chain([0], myList), itertools.chain(myList, [999999999]))]
    
    >>> import itertools
    >>> myList = [9, 44, 99]
    >>> [(i+1, j) for i,j in itertools.izip(itertools.chain([0], myList), itertools.
    chain(myList, [999999999]))]
    [(1, 9), (10, 44), (45, 99), (100, 999999999)]
    

