(spans: Iterable[Tuple[int, int]])
Merge potentially overlapping positive spans to continues ones.
Merge potentially overlapping positive spans to continues ones.
Merge potentially overlapping positive spans to continues ones .
def _merge_spans(spans: Iterable[Tuple[int, int]]) -> Iterable[Tuple[int, int]]:
  """Merge potentially overlapping positive spans to continues ones."""
  last_end = -1
  last_start = -1
  for i_start, i_end in sorted(spans, key=lambda s: s[0]):
    if i_start > last_end:
      if last_end > last_start:
        yield (last_start, last_end)
      last_start = i_start
      last_end = i_end
    else:
      last_end = max(last_end, i_end)
  if last_end > last_start:
    yield (last_start, last_end)
def _merge_spans ( spans : Iterable [ Tuple [ int , int ] ] ) -> Iterable [ Tuple [ int , int ] ] : last_end = - 1 last_start = - 1 for i_start , i_end in sorted ( spans , key = lambda s : s [ 0 ] ) : if i_start > last_end : if last_end > last_start : yield ( last_start , last_end ) last_start = i_start last_end = i_end else : last_end = max ( last_end , i_end ) if last_end > last_start : yield ( last_start , last_end )