1 def pmt(s): 2 """ 3 :param s: the string to get its partial match table 4 :return: partial match table 5 """ 6 prefix = [s[:i + 1] for i in range(len(s) - 1)] 7 suffix = [s[i + 1:] for i in range(len(s) - 1)] 8 intersection = set(prefix) & set(suffix) 9 if intersection: 10 return len(max(intersection)) 11 else: 12 return 0 13 14 def kmp(source, target): 15 for i in range(len(source)): 16 pass