I'm trying to strip the last character in a string if when the string is split by spaces the last element has a length of 1. I then want to put that letter in front of the rest of the other elements.
So, if I had a value of 1st Street W, I would like to convert it to W 1st Street
I'm using this code in the "Pre-Logic Script Code" box in ArcMap field calculator:
def getPrefix(Street_Name):
if len(!Street_Name!.split(" ")[-1])==1:
!StreetName2! = !Street_Name!.split(" ")[-1] + " " + !Street_Name!.split(" ")[0:-1]
And in the box below that:
def getPrefix(!StreetName2!)
I'm getting an error 000989, syntax indention error, but I have everything at two spaces in cascading from calling the function. Pretty sure that's the ESRI specification for the field calculator.
Street_Namebut you're actually using!Street_Name!inside the function. – Dan C Oct 03 '17 at 17:37StreetName2 = '{} {}'.format(Street_Name.split(" ")[-1],Street_Name.split(" ")[0:-1])Use
StreetName2 = '{} {}'.format(Street_Name.split(" ")[-1],' '.join(Street_Name.split(" ")[0:-1]))EDIT - sorry I have no idea how to make it enter on a different space. Also, added join instead of *. – isamson Oct 03 '17 at 19:54