Sha256: 52a698b0db8c23e113b4346b1c41df69b56bbc7d9422dcab9cde942d06721019

Contents?: true

Size: 597 Bytes

Versions: 123

Compression:

Stored size: 597 Bytes

Contents

import re


re_cons = re.compile('^([^aeiou]?qu|[^aeiouy]+|y(?=[aeiou]))([a-z]*)')
re_vowel = re.compile('^([aeiou]|y[^aeiou]|xr)[a-z]*')


def split_initial_consonant_sound(word):
    return re_cons.match(word).groups()


def starts_with_vowel_sound(word):
    return re_vowel.match(word) is not None


def translate(text):
    words = []
    for word in text.split():
        if starts_with_vowel_sound(word):
            words.append(word + 'ay')
        else:
            head, tail = split_initial_consonant_sound(word)
            words.append(tail + head + 'ay')
    return ' '.join(words)

Version data entries

123 entries across 123 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.179 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.178 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.177 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.176 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.175 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.174 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.173 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.172 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.171 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.170 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.169 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.167 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.166 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.165 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.164 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.163 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.162 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.161 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.160 tracks/python/exercises/pig-latin/example.py