Python: 朴素的字符串匹配算法

#!/usr/bin/env python
#coding: utf-8
'''
docstring for naive_string_matcher  
diret tansalation from book "Introduction to Algorithms-CLRS"      
@author: honghe
'''

def matcher(t, p):
    '''
    :param t: the string to check
    :param p: pattern
    '''
    n = len(t)
    m = len(p)
    for s in xrange(0, n-m+1):
        if p == t[s:s+m]:
            print 'Pattern occurs with shift %d' % s 

你可能感兴趣的:(Python: 朴素的字符串匹配算法)