Menu
Coddy logo textTech

Pattern Finder

Part of the Fundamentals section of Coddy's Python journey — lesson 76 of 77.

challenge icon

Challenge

Medium

Create a function named find_occurrences that:

  1. Takes two string arguments: text and pattern
  2. Counts how many times pattern appears in text, including overlapping occurrences
  3. Returns a tuple containing:
    • A boolean indicating if the pattern was found (True/False)
    • The number of occurrences of the pattern
    • A list of starting positions where the pattern was found

For example, if text is "abababab" and pattern is "aba", your function should return (True, 3, [0, 2, 4]), since "aba" appears at positions 0, 2, and 4.

If the pattern is not found, return (False, 0, []).

About the <strong>pass</strong> keyword: You'll see pass in the default code. It's a Python keyword that means "do nothing" and is used as a placeholder when Python requires an indented code block (like inside a function). You should replace pass with your actual function code.

Try it yourself

def find_occurrences(text, pattern):
    # Write your code here
    pass

# Read input
text = input()
pattern = input()

# Call your function and print the result
result = find_occurrences(text, pattern)
print(result)

All lessons in Fundamentals