Here'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
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 newApn
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.