Created
July 21, 2019 21:37
-
-
Save Cyborg-Model-Z/2a0e49fb16f2306f52958e43fcd87a29 to your computer and use it in GitHub Desktop.
Pig latin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def pig_it(text): | |
| print(text) | |
| def startsvowel(wordlist): | |
| latin_list=[] | |
| for str in wordlist: | |
| if str[0] == "a" or str [0] =="A": | |
| latin_list.append(str + "ay") | |
| elif str[0] == "e" or str[0] == "E": | |
| latin_list.append(str+ "ay") | |
| elif str[0] == "str[0] =="I": | |
| latin_list.append(str+ "ay") | |
| elif str[0] == "o" or str[0] =="O": | |
| latin_list.append(str+ "ay") | |
| str[0] == "u" or str[0] == "U": | |
| latin_list.append(str+ "ay") | |
| else: | |
| latin_list.append(str[1:] + str[0] + "ay") | |
| latin_list | |
| def splitsentence(str): | |
| return str.split() | |
| def combinewords(latinlist): | |
| joined = str(" ".join(latinlist)) | |
| return (joined) | |
| pig_it(combinewords(startsvowel(splitsentence("To sit in solemn silence")))) |
Author
Author
Codewars.com/kata/simple-pig-latin/train/python
lol your pig_it function is just print.
Just because you write pig_it(combinewords(startsvowel(splitsentence(... doesn't mean that is what the tests look at.
One principle people use is called DRY (don't repeat yoursef). One example of this is your whole loop for vowels...
Could be:
for str in wordlist:
if str[0] in "aAeEiIoOuU":
latin_list.append(str + "ay")
else:
latin_list.append(str[1:] + str[0] + "ay")
And even that won't work for something like "phlegm", which I assume should be "egmphlay". :D
Also I'm still repeating the + "ay", which always needs to be added...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Camsbury
Ive got to figure out how to move punctuation. Im also getting a weird situation where tests arent passing as pig latin just as the original string. Any ideas?