Every Place It Appears

Python for AIMedium+10 XP+10

Every Place It Appears

.find() only tells you where a piece of text first appears. A search tool needs every place.

Task: write find_all(text, piece) that returns a list of every position where piece starts in text, from left to right.

  • Matches can overlap. In "aaaa", the piece "aa" starts at 0, 1 and 2. (This is different from .count(), which skips overlaps.)
  • piece is never empty.
  • If there are no matches, return [].

Examples

text = "banana"
piece = "an"
returns [1, 3]
text = "aaaa"
piece = "aa"
returns [0, 1, 2]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run