@@ -17,10 +17,10 @@ def translate(text: str) -> str:
1717 :return: The text translated to Pig Latin
1818 """
1919 words : list [str ] = text .split (" " )
20- return " " .join (process_words (word ) for word in words )
20+ return " " .join (process_word (word ) for word in words )
2121
2222
23- def process_words (text : str ) -> str :
23+ def process_word (text : str ) -> str :
2424 """
2525 Process a single word and convert it to Pig Latin using the four translation rules.
2626
@@ -54,7 +54,7 @@ def process_words(text: str) -> str:
5454 return f"{ text [i :]} { text [:i ]} ay"
5555
5656 # Rule 2
57- if is_consonant (text [0 ]):
57+ if not is_vowel (text [0 ]):
5858 # If a word begins with one or more consonants, first move those consonants
5959 # to the end of the word and then add an "ay" sound to the end of the word.
6060 i = get_consonant_cluster_length (text )
@@ -106,16 +106,6 @@ def is_vowel(char: str) -> bool:
106106 return char in "aeiou"
107107
108108
109- def is_consonant (char : str ) -> bool :
110- """
111- Check if a character is a consonant (one of the 21 non-vowel letters).
112-
113- :param char: The character to check
114- :return: True if the character is a consonant, False otherwise
115- """
116- return char .isalpha () and not is_vowel (char )
117-
118-
119109def get_consonant_cluster_length (text : str ) -> int :
120110 """
121111 Find the length of the consonant cluster at the beginning of a word.
@@ -125,7 +115,7 @@ def get_consonant_cluster_length(text: str) -> int:
125115 """
126116 i = 0
127117 for n , char in enumerate (text ):
128- if is_consonant (char ):
118+ if not is_vowel (char ):
129119 i = n
130120 else :
131121 break
0 commit comments