python - Rearrange position of words in string conditionally -


i've spent last few months developing program company using clean , geocode addresses on large scale (~5,000/day). functioning adequately well, however, there address formats see daily causing issues me.

addresses format such park avenue 1 causing issues geocoding. thought process tackle issue follows:

  1. split address list
  2. find index of delimiter word in list. delimiter words words such avenue, street, road, etc. have list of these delimiters called patterns.
  3. check see if word following delimiter composed of digits length of 4 or less. if number has length of higher 4 zip code, not need. if it's less 4 house number.
  4. if word meets criteria explained in previous step, need move first position in list.
  5. finally, put list string.

here initial attempt @ putting thoughts code:

patterns ['my list of delimiters'] address = 'park avenue 1'    # example address address = address.split(' ') pattern in patterns:     location = address.index(pattern) + 1     if address[location].isdigit() , len(address[location]) <= 4:         # here i'm getting bit confused         # way go moving word first position in list address = ' '.join(address) 

any appreciated. thank folks in advance.

make string address[location] list wrapping in brackets, concatenate other pieces.

address = [address[location]] + address[:location] + address[location+1:] 

an example:

address = ['park', 'avenue', '1'] location = 2 address = [address[location]] + address[:location] + address[location+1:]  print(' '.join(address)) # => '1 park avenue' 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -