AnsweredAssumed Answered

A better way to parse an address?

Question asked by jborgion Champion on Aug 12, 2015
Latest reply on Jun 19, 2017 by tkowal

I looked at the standardize address tool to see if it would do what I need and it works for most of my address data, but there are a number that don't fit the perfect model.( See Error Trapping )


At any rate, holding the rank of Hack Specialist .1 in the Python Legion, I'm running a series of scripts to parse out address components from a single string address in the form of


1234 S Main ST or 1234 E Olive Branch Dr or 1234 S 300 E


The house number, pre-dir and suf-type/suf-dir aren't too bad, but teasing the street itself out is a little more challenging  as it may be multiple words.  What I've come up with is a series of splits and joins that get the job done, but there has got to be a better way.  Any pointers are appreciated.


Here is what I do:

def myStreetName(inString):
  a = inString.split(' ')
  b = a.pop()                    #takes off suf
  c = ' '.join(a)                  # put it back together
  d = c.split(' ')                 #split it back out again
  e = d.pop(0)                 #takes off housenum
  f = ' '.join(d)                  #put it back together again
  g = f.split(' ')                 # split again
  h = g.pop(0)                 # get rid of pre-dir
  street = ' '.join(g)          #leaves just the street
  return street                 #home free