Given a sentence in 'bird language', where there are two rules:
- After each consonant there is a random vowel added. For example if the consonant is "l" it will end as "la" or "le"...
After each vowel there are two extra vowels which are the same as the first. For example if there is a "u" it will end as "uuu"
- Vowels are "aeiouy"
hoooowe yyyooouuu duoooiiine→
how you doin
aaa bo cy da eee fe→
a b c d e f
The code is:
VOWELS = "aeiouy" def translate(phrase): result = "" num_of_letters_to_ignore = 0 for i, letter in enumerate(phrase): if num_of_letters_to_ignore > 0: num_of_letters_to_ignore -= 1 continue if letter in VOWELS: num_of_letters_to_ignore += 2 elif letter.isalpha(): num_of_letters_to_ignore += 1 result += letter return result
How can it be improved?
EDIT: I have added the first sentence which was missing where it is correctly specified that y is in the vowels!