python统计两个字符串从首字符开始最大连续相同的字符数
在python中统计两个字符串从首字符开始最大连续相同的字符数,函数如下:
def get_num(s1, s2): num = 0 len_s1 = len(s1) list_s1 = [] for i in range(len_s1): two_s1 = s1[0:i+1] list_s1.append(two_s1) for i in list_s1: if s2.startswith(i) and len(i) > num: num = len(i) return num