#Write a method the takes in a string and returns the pig latin equivalent. #Pig Latin takes the first consonant, moves it to the end of the word and places #“ay” at the end. If the string starts with a consonant do nothing. “pig” = “igpay”, #“banana” = “ananabay” text = "Here is a string" def pig_latin(text): new_text = [] if text.find(" "): text_split = text.split(" ") for i in text_split: first_letter = i[0] i = i.replace(i[0], "") i = i + first_letter + "ay" new_text.append(i) return new_text else: first_letter = text[0] text = text.replace(text[0], "") text = text + first_letter + "ay" return text pig_latin(text)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question