编程语言
首页 > 编程语言> > (python)字符串中找出连续最长的数字串

(python)字符串中找出连续最长的数字串

作者:互联网

代码:

def long_num(str):
    max_list = []
    
    for i in range(len(str)):
        new_list = []
        for j in range(i+1,len(str)):
            if str[j].isdigit():
                new_list.append(str[j])
            else:
                break
            if len(max_list) < len(new_list):
                max_list = new_list
    return "".join(max_list)

测试:

s = "124241htjrjr797rgrrw1575373573733"
print(long_num(s))

结果:

1575373573733

标签:数字串,python,max,list,len,num,str,字符串,new
来源: https://www.cnblogs.com/Durant0420/p/16169371.html