Python面试题-在字符串中找出连续最长的数字串

在字符串中找出连续最长的数字串

 

def FindMaxLenNumSeq(str):

    numlist1=[]

    numlist2=[]



    for char in str:

        try:

            int(char)

            numlist1 += char
    
        except:

            if len(numlist2) > len(numlist1):

                pass
        
            else:

                numlist2 = numlist1
                numlist1 = []



    return numlist2



if __name__ == '__main__':

    str = FindMaxLenNumSeq("012k35abc12defg3546xyz12")

    print(str)

 

你可能感兴趣的:(Python常见面试题)