Python Workout — A “Pig Latin” function that handles interpunction

Eric van Rees
Sep 22, 2022

--

Today’s exercise was the following, a variation on the existing “Pig Latin” function covered earlier:

“If a word ends with punctuation, then that punctuation should be shifted to the end of the translated word.”

What is interesting for this exercise is that there is a Python object that has all interpunction characters stored inside it. It is found in the string module that should be imported first. This object saves you the time and effort to write one yourself. Storing that string to a Python object named “interpunction” makes it easy to extend the existing Pig Latin function:

As you can see in the output, all interpunction from the different input is moved to the end of the newly created output:

--

--

Eric van Rees

Writer and editor. Interested in all things geospatial.