Skip to content

Instantly share code, notes, and snippets.

from typing import Iterable, List, Mapping, Tuple, Generator
def find_all(text: str, pattern: str, start: int = 0) -> Generator[int, None, None]:
"""Generates all the positions of `pattern` as a substring of `text`, starting from index at least `start`."""
while True:
start = text.find(pattern, start)
if start == -1:
return
yield start

Keybase proof

I hereby claim:

To claim this, I am signing this object: