Guest User

Untitled

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