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
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.