Created
November 18, 2014 21:53
-
-
Save abele/05e4ae6cb0162153dc7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def test_with_with_vowels_ends_with_hey(): | |
assert pig_latin('egg') == 'eggway' | |
def test_handle_words_with_consonants(): | |
assert pig_latin('happy') == 'appyhay' | |
def test_handle_words_with_multiple_consonants(): | |
assert pig_latin('glove') == 'oveglay' | |
VOWEL_SEQ = 'aeiou' | |
CONS_ROOT_RE = re.compile('^(?P<cons>[^{0}]*)(?P<root>.*)$'.format(VOWEL_SEQ)) | |
def pig_latin(word): | |
return ''.join(reversed(cons_split(word))) + sufix(word) | |
def cons_split(word): | |
match = CONS_ROOT_RE.match(word) | |
return match.group('cons'), match.group('root') | |
def sufix(word): | |
return 'way' if word[0] in VOWEL_SEQ else 'ay' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment