Count of Substring [CHALLENGE] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 :)

29th Nov 2017, 11:16 PM
Enyone Christian Achobe
Enyone Christian Achobe - avatar
1 Answer
+ 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)
30th Nov 2017, 12:39 AM
Ghauth Christians
Ghauth Christians - avatar