Exercise 3 solution def find_all(data, pattern): offsets = [] start = 0 while True: i = data.find(pattern, start) if i == -1: return offsets offsets.append(i) start = i + 1 print(find_all(b"abcabcab", b"ab")) # [0, 3, 6] print(find_all(b"aaaa", b"aa")) # [0, 1, 2] print(find_all(b"xyz", b"q")) # [] (Run as written; the output matched the comments.) Explanation: bytes.find(pattern, start) returns the offset of the next match at or after start, or -1 when there is none. Restarting the search at i + 1 (rather than i + len(pattern)) also finds overlapping matches, which is why b"aaaa" contains "aa" at three offsets. Use i + len(pattern) instead if you want non-overlapping matches only.