I've got lots of address style strings and I want to sort them in a rational way.
I'm looking to pad all the numbers in a string so that: "Flat 12A High Rise" becomes "Flat 00012A High Rise", there may be multiple numbers in the string.
So far I've got:
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
Can that be improved - looks pugly to me!