+ 1
Count of Substring [CHALLENGE]
Assume s is a string of lower case characters. Write a program that prints the number of times the string 'bob' occurs in s. For example, if s = 'azcbobobegghakl', then your program should print Number of times bob occurs is: 2 In any language of choice, preference on python though Have Fun :)
1 Antwort
+ 2
//Python
import re
string='azcbobobegghakl'
pattern="bob"
def findall(s,p):
global total
a=r""+p
result=re.search(a,s)
if result:
total+=1
findall(s[result.end()-1::],p)
else:
print(total)
total=0
findall(string,pattern)