(indices)
Group consecutive indices into `(start, stop)` tuple 'ranges'.

    >>> list(ranges([1, 2, 3, 5, 3, 4]))
    >>> [(1, 4), (5, 6), (3, 5)]
Group consecutive indices into `(start, stop)` tuple 'ranges'.
Group consecutive indices into ( start stop ) tuple ranges .
def ranges(indices):
    # type: (Iterable[int]) -> Iterable[Tuple[int, int]]
    """
    Group consecutive indices into `(start, stop)` tuple 'ranges'.

    >>> list(ranges([1, 2, 3, 5, 3, 4]))
    >>> [(1, 4), (5, 6), (3, 5)]

    """
    g = groupby(enumerate(indices), key=lambda t: t[1] - t[0])
    for _, range_ind in g:
        range_ind = list(range_ind)
        _, start = range_ind[0]
        _, end = range_ind[-1]
        yield start, end + 1
def ranges ( indices ) : # type: (Iterable[int]) -> Iterable[Tuple[int, int]] g = groupby ( enumerate ( indices ) , key = lambda t : t [ 1 ] - t [ 0 ] ) for _ , range_ind in g : range_ind = list ( range_ind ) _ , start = range_ind [ 0 ] _ , end = range_ind [ - 1 ] yield start , end + 1