The challenge
Move the first letter of each word to the end of it, then add “ay” to the end of the word. Leave punctuation marks untouched. This string manipulation challenge is similar to other Python exercises like counting smiley faces or finding the intersection of two arrays .
Examples
pig_it('Pig latin is cool') # igPay atinlay siay oolcay
pig_it('Hello world !') # elloHay orldway !
Test cases
Test.assert_equals(pig_it('Pig latin is cool'),'igPay atinlay siay oolcay')
Test.assert_equals(pig_it('This is my string'),'hisTay siay ymay tringsay')
How to write the code in Python
def pig_it(text):
words = text.split(" ")
new_words = []
for word in words:
if word.isalpha():
new_word = word[1:] + word[0] + "ay"
new_words.append(new_word)
else:
new_words.append(word)
return " ".join(new_words)