Skip to content

Instantly share code, notes, and snippets.

Created February 26, 2016 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5885857ecfeef423be7a to your computer and use it in GitHub Desktop.
Save anonymous/5885857ecfeef423be7a to your computer and use it in GitHub Desktop.
def temp(line,flag,pos,lvl=0):
if line[pos].isdigit():
flag[pos]=lvl+1
if pos+1<len(line):
return temp(line,flag,pos+1,lvl+1)
else:
return pos+1,lvl
else:
flag[pos]=0
lvl=0
return pos+1,lvl
def extract_digits(line):
"""
extract longest digit sub-str from line
:param line:
:return:
"""
flag=[0 for x in range(len(line))]
print flag
pos=0
while pos<len(flag):
pos,lvl=temp(line,flag,pos)
print flag
length=max(flag)
if length>0:
pe=flag.index(length)
return line[pe-length+1:pe+1]
else:
return ''
if __name__=='__main__':
print extract_digits('tt2012g2t11111g')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment