I have found times when I need to reorder the text within a field such as in this example with the name being last name, first name.
This can be a simple expression in the Field Calculator using the string.split() operation:
!Name!.split(", ") + ' ' + !Name!.split(", ")
But what about those cases where there may be two or more words?
In this case we can use an if/else statement to determine the number of words in the field and then rearrange accordingly.
Pre-Logic Script Code
def reorder(name): if (len(name.split(" ")) ==2): return name.split(" ") + ' ' + name.split(" ") elif (len(name.split(" ")) ==3): return name.split(" ") + ' ' + name.split(" ") + ' ' + name.split(" ") else: pass
Note: Make sure you set the correct split characters. In the second example it only uses a space and not a comma. Also, the example is only set up for 2 and 3 words. Additional conditional statement can be added to accommodate for you data.