Hi
I am trying to write code that will return all instances of a collection of letters in a string variable...
I can get a count returned, but it does not cater for letters that are used twice... for example
The code returns 3 instances but actually it is 4 - it is not counting the babab as 2 instances.
Any suggestions gratefully received!
Thanks!
I am trying to write code that will return all instances of a collection of letters in a string variable...
I can get a count returned, but it does not cater for letters that are used twice... for example
Code:
s = 'ajsfhbababnsnbabnndbab'
n = s .count (str('bab'))
print 'Number of times bab occurs is: ' + str(n)
Any suggestions gratefully received!
Thanks!
Comment