I have many address style lines and I want to sort them in a rational way.
I am looking to fill in all the numbers in a line so that: "Flat 12A High Rise" becomes "Flat 00012A High Rise", there can be several numbers in a line.
So far I have received:
def pad_numbers_in_string(string, padding=5): numbers = re.findall("\d+", string) padded_string = '' for number in numbers: parts = string.partition(number) string = parts[2] padded_string += "%s%s" % (parts[0], parts[1].zfill(padding)) padded_string += string return padded_string
Could this be improved - it looks monstrous to me!
python string
Ross
source share