Skip to content

Instantly share code, notes, and snippets.

@abele
Created November 18, 2014 21:53
Show Gist options
  • Save abele/05e4ae6cb0162153dc7d to your computer and use it in GitHub Desktop.
Save abele/05e4ae6cb0162153dc7d to your computer and use it in GitHub Desktop.
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