def get_interval_offsets_txt(lines: List[str]) -> Iterator[Tuple[int, int]]:
"""Return all the intervals corresponding to the ``lines``
passed as parameter:
[(0, n), (n, m), …]
where the values are the character position of the beginning and end of
each line, counting from the first character of the file (start at 0)"""
idx_first_char = 0
cumulative_lines_length = list(itertools.accumulate(list(map(len, lines))))
return zip([idx_first_char] + cumulative_lines_length,
cumulative_lines_length)
评论列表
文章目录