0

So I'm curious, how do I find specific combination of word in a continuous string?

I'm really new to python and here's the simplest code I've written.

#find amount of bob(s) in the string
s = 'azcbobobegghakl'
count = 0
for letter in s:
    if letter == 'bob':
        count += 1

print count

The count works fine if letter == 'a single letter', but it won't count the amount of "bob"s that appears in the continuous string (which in this case is 2).

0 Answers0