Question: This was my attempt , I wanted to take a window of 3 letters and walk through the string, But not getting the expected answer of 2 . I am getting into some infinite loop. Wondering why . 

```
def find_bob(s1):
    check_list = 'bob'
    count = 0
    n=0
    cmp_chars=0
    while n<=len(s1):
        while cmp_chars == s1[n:3]:
            if cmp_chars == check_list:
                count += 1
                continue
    return count

s1= 'azcbobobegghakl'
#check_list='bob'
val1 = find_bob(s1)

```

Answer: 
You can use a [regex](https://regex101.com/r/Cli70D/1) with a [zero width lookahead](http://www.rexegg.com/regex-lookarounds.html) and just count the matches:

```
>>> import re
>>> s1= 'azcbobobegghakl'
>>> len([m for m in re.finditer(r'(?=bob)', s1)])
2

```
`Wondering why...`

```
n=0
cmp_chars=0
while n<=len(s1):
    while cmp_chars == s1[n:3]:
        if cmp_chars == check_list:
            count += 1
            continue

```

`n` starts at zero and does not change within the loop so the while condition is always True.

`while cmp_chars == s1[n:3]:` Not sure what to make of this, `cmp_chars` starts at zero and will never equal a string so this loop condition is always False.

Try 

```
while n<=len(s1):
    if s1[n:n+3] == check_list:
        count += 1
    n = n +1

```