Guest User

PS3:1

a guest
Sep 12th, 2011
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. from string import *
  2.  
  3. def countSubStringMatch(target,key):
  4.     """Enter target string and search key string"""
  5.     assert isinstance(target,str), "Target value not string"
  6.     assert isinstance(key,str), "Key value not string"
  7.  
  8.     length=0
  9.     index=0
  10.     count=0
  11.     for i in range(0,len(target)):
  12.         index=target.find(key,index+length)
  13.         length=len(key)
  14.         if index!=-1:
  15.             count+=1
  16.         elif index==-1 and count==0:
  17.             return -1
  18.         else:
  19.             return count
Advertisement
Add Comment
Please, Sign In to add comment