so im looking to write a function that will take input in the form:
123 1st street APT 32S or
320 Jumping Alien Road
555 Google Ave
and output in a dictionary / json all the information parsed from the inputted string
dictionary would look something like
output = {
"streetNum" : "123",
"roadName" : "1st",
"suffix" : "street",
"enders" : "APT", #or None /null
"room" : "32S" #or None / null
}
Im trying to thing of the logic but the best I can come up with is something along the lines of address.split(' ') and then taking where the roadname, suffix, and streetname would typically be located in said string but obviously these things aren't always gonna be located in that order and when road names have spaces inside them that would break the function as well.
def addressParser(addressString):
return {
"streetNum" : addressString.split(' ')[0], #prob need regex help
"roadName" : addressString.split(' ')[1],
"suffix" : addressString.split(' ')[2],
"enders" : addressString.split(' ')[3],
"room" : addressString.split(' ')[4]
}
Edit: found exactly what i needed here https://pypi.org/project/address/