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.

Examples

1
2
pig_it('Pig latin is cool') # igPay atinlay siay oolcay
pig_it('Hello world !')     # elloHay orldway !

Test cases

1
2
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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)