I'm working on cleaning up the openstreetmap data, hope to make it more concise.The goal is to change the following street name in two parts:check to see if (S) is at the end of the name If yes, change (S) to South Move South to the front Check again, change Rd. to RoadLintao Rd. (S) => South Lintao RoadThis is what I have for now. It's working fine, but I feel like going over too many steps. How to best shorten the process? Since there will be hundreds of thousands record. Best to speed up if possible. street_type_re = re.compile(r'\b\S+\.?$', re.IGNORECASE) #check the last part of the streetewsn_street_re = re.compile(r\(([ewsn]|.)*\), re.IGNORECASE) #check if street end has (S) and similar parts.if eswn:        if eswn.group() in mapping.keys():            better_street_type = mapping[eswn.group()]            better_name = ewsn_street_re.sub(better_street_type, name)        st_list = better_name.split() #split name into list        old_end = st_list[-1] #store the old last part        del st_list[-1] #del the old part        st_list.insert(0, old_end)         not_better_name = ' '.join(st_list)        d = street_type_re.search(not_better_name)         #another round change the Rd. into Rod        if d:            if d.group() in mapping.keys():                better_street_type = mapping[d.group()]                better_name = street_type_re.sub(better_street_type, not_better_name)
Systematically reordering parts of street names and replacing abbreviations
python;regex