def count1(x):
count = 0
for i in range(len(x)):
if x[i:i + 2] == 'ba':
count += 1
return count
| Function Call | Return Value | |||
|---|---|---|---|---|
| count1('baba') | → | |||
| count1('aba') | → | |||
| count1('baaabab') | → | |||
| count1('abc') | → | |||
| count1('goodbye') | → | |||
| count1('a') | → | |||
| count1('ba') | → | |||
Experiment with this code on Gitpod.io