You have to build the whole sentence in some way. For example, you can build up a list of words:
pig_words = []
for word in sentence.split():
if word[0] in VOWELS:
pig_latin = word + "ay"
else:
pig_latin = word[1:] + word[0] + "ay"
pig_words.append(pig_latin)
return pig_words
If you want to turn it back into a sentence, the opposite of split
is join
, so just change the last line to:
return ' '.join(pig_words)