l = [0, 1, 2, 3, 4, 7, 8, 9, 11]
[[t[0][1], t[-1][1]] for t in (tuple(g[1]) for g in itertools.groupby(
    enumerate(l), lambda i_x: i_x[0] - i_x[1]))]
converting a list of integers into range in python