Solved! Go to Solution.
def fix(oldApn):
if '-' not in oldApn:
newApn = ''
else:
apnList = oldApn.split('-')
if len(apnList) == 3:
newApn = apnList[0].lstrip() + '-' + apnList[1].lstrip + '-' + apnList[2].zfill(2)
else:
newApn = apnList[0].lstrip() + '-' + apnList[1].lstrip
return newApnHere's how I would do it, using lists and list comprehensions...
def fix(oldApn):
# find integer pieces in "-" delimited string, skipping zeros
pieces = [str(int(p)) for p in oldApn.split("-") if p.isdigit()]
newApn = "-".join([p for p in pieces if p != "0"])
return newAPn