Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
re.sub solution in Clear category for Bird Language by soshi-matsuo
import re
VOWELS = "aeiouy"
def translation(phrase):
words = phrase.split()
human_lang = []
for word in words:
remove_vowel = re.sub(r'([b-df-hj-np-tv-xz])[aeiouy]', r'\1', word) # hi,la → h,l
new_word = re.sub(r'([aeiouy]){3}', r'\1', remove_vowel) # aaa,ooo → a, o
human_lang.append(new_word)
return ' '.join(human_lang)
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert translation("hieeelalaooo") == "hello", "Hi!"
assert translation("hoooowe yyyooouuu duoooiiine") == "how you doin", "Joey?"
assert translation("aaa bo cy da eee fe") == "a b c d e f", "Alphabet"
assert translation("sooooso aaaaaaaaa") == "sos aaa", "Mayday, mayday"
March 12, 2019