This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def remove_spans_gen(s, spans): | |
checker = make_range_checker(spans); next(checker) | |
return ''.join(c for (i, c) in enumerate(s) if not checker.send(i)) | |
def make_range_checker(spans): | |
idx = yield | |
for (i, j) in spans: | |
while idx < j: | |
idx = (yield i <= idx < j) | |
while True: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import chain, starmap | |
def remove_spans(s, spans): | |
to_drop = set(chain(*starmap(range, spans))) | |
return ''.join(c for (i, c) in enumerate(s) if i not in to_drop) |
NewerOlder