Created
January 27, 2017 18:13
-
-
Save andela-sjames/2697aeb299bc66a51f72f6acdd9c01f1 to your computer and use it in GitHub Desktop.
This file contains 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 is_consonant(char): | |
return char not in "aeiouAEIOU" | |
def pigLatin(word): | |
""" | |
Translate a single lowercase word to pig Latin. | |
if w begins with a consonant, | |
move the leading consonant to the end of the word | |
add 'ay' as a suffix | |
if w begins with a vowel, | |
add 'yay' as a suffix | |
'y' is a vowel; 'y' is not a consonant. | |
Test data (you should add more): | |
input: 'pig' output: 'igpay' | |
input: 'eagerly' output: 'eagerlyyay' | |
Params: w (string) a single lowercase English word (all alphabetic letters) | |
Returns: (string) w in pig Latin | |
""" | |
# INSERT YOUR CODE HERE, replacing 'pass' | |
from collections import deque | |
string_array = [] | |
# return initial str + "way" if it starts with vowel | |
# if not - convert str to array | |
if not is_consonant(word[0]): | |
return word + "yay" | |
else: | |
# import pdb ; pdb.set_trace() | |
string_array = list(word) | |
while is_consonant(string_array[0]): | |
val = string_array[0] | |
string_array = string_array[1:] | |
string_array.append(val) | |
return "".join(string_array) + "ay"; | |
print pigLatin('eagerly') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment