Created
November 10, 2022 02:04
-
-
Save goddoe/6521d3d91873a4190bc97dea3d1d661e to your computer and use it in GitHub Desktop.
find_all_span.py
This file contains 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 find_all_span(d, s): | |
span_list = [] | |
offset = -1 | |
while True: | |
start_idx = d.find(s, offset + 1) | |
if start_idx == -1: | |
break | |
end_idx = start_idx + len(s) | |
span_list.append({"text": s, | |
"answer_ch_idx": [start_idx, end_idx]}) | |
offset = start_idx | |
return span_list | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment