Skip to content

Instantly share code, notes, and snippets.

@Cyborg-Model-Z
Created July 21, 2019 21:37
Show Gist options
  • Select an option

  • Save Cyborg-Model-Z/2a0e49fb16f2306f52958e43fcd87a29 to your computer and use it in GitHub Desktop.

Select an option

Save Cyborg-Model-Z/2a0e49fb16f2306f52958e43fcd87a29 to your computer and use it in GitHub Desktop.
Pig latin
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"))))
@Cyborg-Model-Z
Copy link
Author

@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?

@Cyborg-Model-Z
Copy link
Author

Codewars.com/kata/simple-pig-latin/train/python

@Camsbury
Copy link

lol your pig_it function is just print.

@Camsbury
Copy link

Just because you write pig_it(combinewords(startsvowel(splitsentence(... doesn't mean that is what the tests look at.

@Camsbury
Copy link

Camsbury commented Jul 23, 2019

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