def _apply_substitutions(content: str, subs: list[Substitution]) -> str:
    """
    Returns a copy of content with all of the substitutions applied.
    Uses a single pass for efficiency.
    """
    cursor = 0
    segments: list[str] = []

    for (start, end), replacement in sorted(subs, key=lambda x: x[0][0]):
        in_between = content[cursor:start]
        segments.extend((in_between, replacement))
        cursor += len(in_between) + (end - start)

    segments.append(content[cursor:])

    return "".join(segments)

    Returns a copy of content with all of the substitutions applied.
    Uses a single pass for efficiency.
    
poethepoet/helpers/python.py