Guest User

Untitled

a guest
Jun 23rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. ##Write two functions, called countSubStringMatch  and countSubStringMatchRecursive that
  2. #take two arguments, a key string and a target string.  These functions iteratively and recursively count
  3. ##the number of instances of the key in the target string. You should complete definitions for
  4. #def countSubStringMatch(target,key):
  5. #and
  6. #def countSubStringMatchRecursive (target, key)
  7.  
  8.  
  9. ## This is the iterative one .
  10.  
  11.  
  12.  
  13. from string import *
  14. def stringgen():## Calling function.
  15.     target1 = 'atgacatgcacaagtatgcat'
  16.     target2 = 'atgaatgcatggatgtaaatgcag'
  17.     print target1,target2
  18.     a=find(target1,"atgc")
  19.     print a
  20.     countSubStringMatch(target1,"atgc")
  21.    
  22. def countSubStringMatch(target,key):
  23.                     ''' Finds the count for the number of matches of a substring'''
  24.      count=0
  25.      pointer=0
  26.      pointerlist=[]
  27.      print len(target)
  28.      
  29.      while(pointer<len(target)):
  30.          pointer=find(target[pointer:],key)# initially pointer zero, and then takes slices off the input string for further comparison
  31.          if pointer==-1:# No match scenario
  32.              break
  33.          if pointer!=-1:# Match scenario
  34.              pointerlist.append(pointer)# create a list of match locations
  35.              print pointer
  36.              count+=1
  37.              print target[pointer:]
  38.              raw_input()
  39.          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? :?
  40.  
  41.      ## To print the list of locations with a match and the number of instances of match    
  42.      for i in pointerlist:
  43.          print 'List elements',i
  44.      print 'Count',count
Add Comment
Please, Sign In to add comment