Given a number texted string like '0104002' I need a return
for x in num:
if y>0: break
This seems like something which is trivial for a regex:
>>> import re >>> re.match(r'^(0*[^0]+)0+([^0].*)$', '0104002').groups() ('01', '4002')
This regex defines two groups which are split by one or more zeroes. The split is defined by the first series of zeroes to appear after the first series of non-zeroes. What comes before that split falls into the first group, and what comes after that falls into the second group.
For anyone who finds regex intimidating, here's the "verbose" explanatory version.
re.match( r'''^ ( # Begin first group 0* # Allow for some number of leading zeroes [^0]+ # Match a series of non-zeroes ) # End first group 0+ # Match some series of zeroes (the separator) ( # Begin second group [^0] # Match the first non-zero character .* # Match anything afterward ) # End second group $ ''', '0104002', flags=re.VERBOSE).groups()