DEV Community

Discussion on: Daily Challenge #22 - Simple Pig Latin

Collapse
 
peter279k profile image
peter279k

Here is the simple solution with Python:

def pig_it(text):
    answer = ""
    pig_prefix = "ay"

    text_list = text.split(' ')

    for text in text_list:
        first_text = text[0]

        start_index = 1
        if len(text) == 0:
            start_index = 0

        if first_text == "?" or first_text == "!" or first_text == "," or first_text == ".":
            answer += text
        else:
            answer += text[start_index:] + first_text + pig_prefix + " " 

    if answer[-1] == " ":
        return answer[0:-1]

    return answer