Select to view content in your preferred language

# Move last word to first word in field calculator

2067
12
10-21-2021 08:50 AM
by
New Contributor II

Hi!

I'm trying to give watercourse names their French name from their English name, so I need to change the order of words a bit such as:

Wind Ruisseau -> Ruisseau Wind

I can remove Ruisseau with !Nom![:-9], but I can't figure out how to place it in the front with a space.

Some watercourse names hare three words like

West Wind Ruisseau

Would using an UpdateCursor be more simple than trying to figure out an expression in the Field Calculator?

Thanks!

Tags (3)
1 Solution

Accepted Solutions
MVP Esteemed Contributor
``````>>> s = "Wind Ruisseau"
>>> " ".join(s.split()[::-1])
'Ruisseau Wind'
>>>``````
12 Replies
by
MVP Regular Contributor

"West Wind"+' ' +"Ruisseau"

Amanda Bishop, GISP
by
New Contributor II

I need to do it for thousands of unique names that end with "Ruisseau" and make them start with "Ruisseau"

by
MVP Regular Contributor

Are the unique names in a specific field you can call out?  In this case, you could use the field calculator  to do this:

"Ruisseau"+' ' +[FIELD NAME]

Amanda Bishop, GISP
by
New Contributor II

Ah yes, that's a much more simple solution than I was thinking. I think this should work, thank you!

MVP Esteemed Contributor
``````>>> s = "Wind Ruisseau"
>>> " ".join(s.split()[::-1])
'Ruisseau Wind'
>>>``````
by
New Contributor II

Thanks! I'll give this a try as well.

Can I make my field equal s?  like  s = !Nom! so it selects my selected rows from this field?

by
New Contributor II

Just tried with field name, which absolutely works! Thanks kindly.

by
New Contributor II

Hi Joshua,

Is there a way to I could keep the order of the middle words when there are three words in the string?

For example, this expression also reverses the names of the other words:

'West Wind Ruisseau' becomes 'Ruisseau Wind West'

and I would like 'Ruisseau West Wind'

MVP Regular Contributor

Here's another solution to consider.

``````s = "West Wind Ruisseau"
s = s.rsplit(" ", 1)
last_word = s.pop()
s = " ".join([last_word] + s)``````