Every substring-search engine starts with the obvious idea: try the pattern at every position.
Implement naive_search(text, pattern) that returns a list of every start index where pattern occurs inside text, scanning left to right.
Matches may overlap. For example, searching for aa inside aaaa yields indices [0, 1, 2] because the pattern starts at three overlapping positions.
Rules:
def naive_search(text, pattern):
"""Return all start indices where pattern occurs in text (overlaps allowed)."""
# TODO: slide a window of len(pattern) across text and collect matches
pass
The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.
Every substring-search engine starts with the obvious idea: try the pattern at every position.
Implement naive_search(text, pattern) that returns a list of every start index where pattern occurs inside text, scanning left to right.
Matches may overlap. For example, searching for aa inside aaaa yields indices [0, 1, 2] because the pattern starts at three overlapping positions.
Rules:
Press Run Tests or ββ© to check your solution.