"""
Convert a phrase to piglatin.
(Version 2 : minimalist)
Usage:
$ python piglatin2.py
Type a lowercase phrase without punctuation: does it try things
oesday itway tryay ingsthay
Nonalphabetic characters or uppercase are not treated gracefully,
so only type lowercase and spaces.
Jim Mahoney | mahoney@marlboro.edu | Aug 2012 | GPL
"""
import re
def word2pig(word):
""" Convert a word to piglatin """
if word[0] in "aeiou":
return word + "way"
else:
match = re.match("^([^aeiou]+)([aeiou].*)$", word)
if match:
return match.group(2) + match.group(1) + "ay"
else:
return word + "ay"
phrase = raw_input("Type a lowercase phrase without punctuation: ")
print ' '.join(map(word2pig, phrase.split(' ')))
syntax highlighted by Code2HTML, v. 0.93pm6