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.119 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.118 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.117 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.116 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.115 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.114 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.113 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.111 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.110 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.109 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.108 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.107 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.106 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.105 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.104 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.103 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.102 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.101 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.100 tracks/python/exercises/pig-latin/example.py
trackler-2.2.1.99 tracks/python/exercises/pig-latin/example.py