daily pastebin goal
48%
SHARE
TWEET

Untitled

puchiedarcy Nov 22nd, 2016 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. def match(pattern, txt):
  3.   patternLen = len(pattern)
  4.   txtLen = len(txt)
  5.   if pattern is None or txt is None:
  6.     return False
  7.   if pattern == ‘’:
  8.     return True
  9.   if txtLen == 0:
  10.     return False
  11.   if patternLen > txtLen:
  12.     return False
  13.  
  14.  
  15.   terminus = txtLen - patternLen
  16.   patternIndex = 0  
  17.   isMatching = False
  18.  
  19.  
  20.   for txtChar in txt:
  21.     if txtChar == pattern[patternIndex]:
  22.         isMatching = True
  23.         patternIndex++
  24.         if patternIndex == patternLen:
  25.             return True
  26.     else:
  27.         if patternIndex > txtLen - terminus:
  28.             return False
  29.         patternIndex = 0
  30.         isMatching = False
  31.  
  32.  
  33.  
  34.  
  35.   return False
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top