Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##Write two functions, called countSubStringMatch and countSubStringMatchRecursive that
- #take two arguments, a key string and a target string. These functions iteratively and recursively count
- ##the number of instances of the key in the target string. You should complete definitions for
- #def countSubStringMatch(target,key):
- #and
- #def countSubStringMatchRecursive (target, key)
- ## This is the iterative one .
- from string import *
- def stringgen():## Calling function.
- target1 = 'atgacatgcacaagtatgcat'
- target2 = 'atgaatgcatggatgtaaatgcag'
- print target1,target2
- a=find(target1,"atgc")
- print a
- countSubStringMatch(target1,"atgc")
- def countSubStringMatch(target,key):
- ''' Finds the count for the number of matches of a substring'''
- count=0
- pointer=0
- pointerlist=[]
- print len(target)
- while(pointer<len(target)):
- pointer=find(target[pointer:],key)# initially pointer zero, and then takes slices off the input string for further comparison
- if pointer==-1:# No match scenario
- break
- if pointer!=-1:# Match scenario
- pointerlist.append(pointer)# create a list of match locations
- print pointer
- count+=1
- print target[pointer:]
- raw_input()
- pointer+=1# End of while loop , supposed to cycle through input string but not happening, going into infinite loop , any idea why this could be happening? :?
- ## To print the list of locations with a match and the number of instances of match
- for i in pointerlist:
- print 'List elements',i
- print 'Count',count
Add Comment
Please, Sign In to add comment