Question:
A string contains bulb string along with others, sometime, it is the continuous one like bulbulb
. Find the number of occurrences of bulb
.
Ex:
Given: "fbulbhdskjfhdskbulbdsfkjdshfdskbulbulbdsfsdfds"
Expected: 4
Solution:
count = 0
for i, c in enumerate(bulb_str):
if c == "b" and (bulb_str[i:i+4]) == "bulb":
count += 1
print(count)
Top comments (0)