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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM