Showing posts with label count of substring in string. Show all posts
Showing posts with label count of substring in string. Show all posts

19 Jan 2015

Count of Substring in String

#Python
'''
Count the number of times the substring 'bob' appears in string s

'''


s='azcbobobegghakl'
i=0
ocr=0
while(i<(len(s)-2)):
    ocr+=s.count('bob',i,i+3)
    i+=1      
print "Number of times bob occurs is:", ocr     



Categories: ,

Copyright © UPgradeCODING | Powered by Blogger