def extract_ranges(index_list, range_size_limit=32):
    'Extract consecutive ranges and singles from index_list.\n\n  Args:\n    index_list: List of monotone increasing non-negative integers.\n    range_size_limit: Largest size range to return.  If a larger\n      consecutive range exists, it will be returned as multiple\n      ranges.\n\n  Returns:\n    (ranges, singles) where ranges is a list of [first, last] pairs of\n      consecutive elements in index_list, and singles is all of the\n      other elements, in original order.\n  '
    if (not index_list):
        return ([], [])
    first = index_list[0]
    last = first
    ranges = []
    singles = []
    for i in index_list[1:]:
        if ((i == (last + 1)) and ((last - first) <= range_size_limit)):
            last = i
        else:
            if (last > first):
                ranges.append([first, last])
            else:
                singles.append(first)
            first = i
            last = i
    if (last > first):
        ranges.append([first, last])
    else:
        singles.append(first)
    return (ranges, singles)
Extract consecutive ranges and singles from index_list.

Args:
  index_list: List of monotone increasing non-negative integers.
  range_size_limit: Largest size range to return.  If a larger
    consecutive range exists, it will be returned as multiple
    ranges.

Returns:
  (ranges, singles) where ranges is a list of [first, last] pairs of
    consecutive elements in index_list, and singles is all of the
    other elements, in original order.
def extract_ranges(index_list, range_size_limit=32):
    'Extract consecutive ranges and singles from index_list.\n\n  Args:\n    index_list: List of monotone increasing non-negative integers.\n    range_size_limit: Largest size range to return.  If a larger\n      consecutive range exists, it will be returned as multiple\n      ranges.\n\n  Returns:\n    (ranges, singles) where ranges is a list of [first, last] pairs of\n      consecutive elements in index_list, and singles is all of the\n      other elements, in original order.\n  '
    if (not index_list):
        return ([], [])
    first = index_list[0]
    last = first
    ranges = []
    singles = []
    for i in index_list[1:]:
        if ((i == (last + 1)) and ((last - first) <= range_size_limit)):
            last = i
        else:
            if (last > first):
                ranges.append([first, last])
            else:
                singles.append(first)
            first = i
            last = i
    if (last > first):
        ranges.append([first, last])
    else:
        singles.append(first)
    return (ranges, singles)