Strategies for searching through strings in python?
Question: What are efficient ways to search for substrings in strings? \- Are there
specific functions built in python we can use? \- Can we convert them to lists
then access elements in the list? \- Can we use for loops to search through
individual elements? \- Is there one generally accepted method by Python
programmers?

It would be helpful to understand the different strategies to help me solve
the following problem:

Return the number of times that the string `"code"` appears anywhere in the
given string, except we'll accept any letter for the `'d'`, so `"cope"` and
`"cooe"` count.

    
    
    count_code('aaacodebbb') → 1
    count_code('codexxcode') → 2
    count_code('cozexxcope') → 2
    


Answer: You can use `regex`:

    
    
    >>> import re
    def count(s):
        return sum(1 for m in re.finditer(r'co.e', s))
    ... 
    >>> count('aaacodebbb')
    1
    >>> count('codexxcode')
    2
    >>> count('cozexxcope')
    2
    

Here `.` matches any character, if you only want to match alphabets then use
`r'co[a-zA-Z]e'`.

