Splits a string on whitespaces and records the indices of each in the original string. @:return generator((word, (start_idx, end_idx)), ...)
(s)
| 69 | |
| 70 | # https://stackoverflow.com/questions/13734451/string-split-with-indices-in-python |
| 71 | def split_indices(s): |
| 72 | """Splits a string on whitespaces and records the indices of each in the original string. |
| 73 | @:return generator((word, (start_idx, end_idx)), ...) |
| 74 | """ |
| 75 | return ((m.group(0), (m.start(), m.end() - 1)) for m in re.finditer(r"\S+", s)) |
| 76 | |
| 77 | |
| 78 | def word_ngrams_indices(s, n): |
no outgoing calls
no test coverage detected