Converting to PigLatin With Python

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.


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"
    return " ".join(new_words)