Select to view content in your preferred language

Move text after comma

1947
11
12-18-2020 10:06 AM
2Quiker
Frequent Contributor

I have a table and in that table I have field Fld_1 and I would like to move the text after the comma to the front of the attribute and remove the comma. Not all attributes will have a comma.

I am able to split the filed attrubutes but am not sure how to work with the comma ','.

with arcpy.da.UpdateCursor(Table, ['Fld_1']) as cursor:
for row in cursor:
row[0] = " ".join(row[0].split()[:3])
cursor.updateRow(row)
del cursor

 

Example

Island Village, The --> The Island Village

 

 

 

11 Replies
DanPatterson
MVP Esteemed Contributor

You guys...

golf_code.png


... sort of retired...
DanPatterson
MVP Esteemed Contributor
" ".join([i.strip() for i in a.split(",")][::-1])  # ---- forgot list comprehensions

... sort of retired...