Skip to content

Instantly share code, notes, and snippets.

@goddoe
Created November 10, 2022 02:04
Show Gist options
  • Save goddoe/6521d3d91873a4190bc97dea3d1d661e to your computer and use it in GitHub Desktop.
Save goddoe/6521d3d91873a4190bc97dea3d1d661e to your computer and use it in GitHub Desktop.
find_all_span.py
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